1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
//+-------------------------------------------------------------------
// File: testsrv.cxx
//
// Contents:
//
// Classes: CBasicSrvCF - IUnknown IClassFactory
// CBasicSrv - IUnknown IPersist IPersistFile IParseDisplayName
//
// Notes: This code is written based on OLE2.0 code. Therefore
// all error codes, defines etc are OLE style rather than Cairo
//
// History: 24-Nov-92 DeanE Created
// 31-Dec-93 ErikGav Chicago port
//---------------------------------------------------------------------
#pragma optimize("",off)
#include <windows.h>
#include <ole2.h>
#include "testsrv.hxx"
#include <stdio.h>
// BUGBUG - memory allocation hacks need these so new and delete don't
// break us
//
#include <malloc.h>
#include <dos.h>
#define IDM_DEBUG 0x100
extern "C" LRESULT FAR PASCAL MainWndProc(HWND, UINT, WPARAM, LPARAM);
void ReportMessage(HWND, WORD);
// This is global because we're still in $%E#$#K 16-bit world
HWND g_hwndMain = NULL;
// Note constructor cannot fail
CTestServerApp tsaMain;
//+--------------------------------------------------------------
// Function: WinMain
//
// Synopsis: Initializes application and controls message pump.
//
// Returns: Exits with exit code 0 if success, non-zero otherwise
//
// History: 25-Nov-92 DeanE Created
//---------------------------------------------------------------
int PASCAL WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszCmdline,
int nCmdShow)
{
static TCHAR szAppName[] = TEXT("OleServer");
MSG msg;
WNDCLASS wndclass;
if (!hPrevInstance)
{
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = MainWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(125));
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (0==RegisterClass(&wndclass))
{
// Error! Clean up and exit
return(LOG_ABORT);
}
}
g_hwndMain = CreateWindow(
szAppName,
TEXT("OLE Server"),
WS_OVERLAPPEDWINDOW | WS_VSCROLL,
GetSystemMetrics(SM_CXSCREEN)/12, // Init X pos
GetSystemMetrics(SM_CYSCREEN)/12, // Init Y pos
GetSystemMetrics(SM_CXSCREEN)*2/3, // width
GetSystemMetrics(SM_CYSCREEN)*2/3, // height
NULL,
NULL,
hInstance,
NULL);
if (NULL==g_hwndMain)
{
// Error! Clean up and exit
return(LOG_ABORT);
}
// Add debug option to system menu
HMENU hmenu = GetSystemMenu(g_hwndMain, FALSE);
AppendMenu(hmenu, MF_SEPARATOR, 0, NULL);
AppendMenu(hmenu, MF_STRING | MF_ENABLED, IDM_DEBUG, TEXT("Debug"));
// Initialize Application
if (S_OK != tsaMain.InitApp(lpszCmdline))
{
tsaMain.CloseApp();
return(LOG_ABORT);
}
if (tsaMain.GetEmbeddedFlag())
{
// We're running as an embedded app
// Don't show the main window unless we're instructed to do so
// BUGBUG - In-place editing is NYI
ShowWindow(g_hwndMain, SW_SHOWMINIMIZED);
}
else
{
// We are not running as an embedded app - show the main window
ShowWindow(g_hwndMain, nCmdShow);
}
UpdateWindow(g_hwndMain);
// message loop
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// Clean up and exit
// BUGBUG - check return code?
tsaMain.CloseApp();
return(0);
}
//+--------------------------------------------------------------
// Function: MainWndProc
//
// Synopsis: Callback for the server window
//
// Returns: Varies dependent on message received.
//
// History: 25-Nov-92 DeanE Created
//---------------------------------------------------------------
extern "C" LRESULT FAR PASCAL MainWndProc(
HWND hwnd,
UINT wMsg,
WPARAM wParam,
LPARAM lParam)
{
switch(wMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return(0);
case WM_USER:
DestroyWindow(hwnd);
return 0;
case WM_SYSCOMMAND:
if (wParam == IDM_DEBUG)
{
// Request for a debug breakpoint!
DebugBreak();
}
default:
break;
}
return(DefWindowProc(hwnd, wMsg, wParam, lParam));
}
void ReportMessage(HWND hwnd, WORD wParam)
{
TCHAR szBuffer[256];
szBuffer[0] = '\0';
switch (wParam)
{
case MB_SHOWVERB:
lstrcpy(szBuffer, TEXT("OLEIVERB_SHOW Received"));
break;
case MB_PRIMVERB:
lstrcpy(szBuffer, TEXT("OLEIVERB_PRIMARY Received"));
break;
default:
lstrcpy(szBuffer, TEXT("Unrecognized ReportMessage code"));
break;
}
MessageBox(hwnd, szBuffer, TEXT("OLE Server"), MB_ICONINFORMATION | MB_OK);
}
|