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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
/***
*winmain.cpp
*
* Copyright (C) 1992-1994, Microsoft Corporation. All Rights Reserved.
* Information Contained Herein Is Proprietary and Confidential.
*
*Purpose:
* This module is the main entry point for the sample IDispatch polygon
* server, spoly2.exe.
*
* This program is intended to demonstrate an implementation of the IDispatch
* interface. Spoly2 is a very simple app, that implements two simple objects,
* CPoly and CPoint and exposes their properties and methods for programatic
* and cross-process access via IDispatch.
*
*Implementation Notes:
*
*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include "spoly.h"
#include "cpoint.h"
#include "cpoly.h"
HINSTANCE g_hinst = 0;
HWND g_hwndFrame = 0;
HWND g_hwndClient = 0;
TCHAR g_szFrameWndClass[] = TSTR("FrameWClass");
CStatBar FAR* g_psb = NULL;
BOOL InitApplication(HINSTANCE);
BOOL InitInstance(HINSTANCE, int);
extern "C" int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
extern "C" long FAR PASCAL FrameWndProc(HWND, UINT, WPARAM, LPARAM);
extern "C" int PASCAL
WinMain(
HINSTANCE hinst,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
int retval;
HRESULT hresult;
if(!hPrevInstance)
if(!InitApplication(hinst))
return FALSE;
if((hresult = InitOle()) != NOERROR)
return FALSE;
if(!InitInstance(hinst, nCmdShow)){
retval = FALSE;
goto LExit;
}
while(GetMessage(&msg, NULL, NULL, NULL)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
g_psb->Release();
CPoly::PolyTerm();
retval = msg.wParam;
LExit:;
UninitOle();
return retval;
}
BOOL
InitApplication(HINSTANCE hinst)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = FrameWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hinst;
wc.hIcon = LoadIcon(hinst, TSTR("SPOLY"));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE+1);
wc.lpszMenuName = TSTR("SPolyMenu");
wc.lpszClassName = g_szFrameWndClass;
if(!RegisterClass(&wc))
return FALSE;
return TRUE;
}
#ifdef WIN32
#define szAppTitle TSTR("IDispatch Polygon Server #2 (32-bit)")
#else //WIN32
#define szAppTitle TSTR("IDispatch Polygon Server #2")
#endif //WIN32
BOOL
InitInstance(HINSTANCE hinst, int nCmdShow)
{
g_hinst = hinst;
// Create a main frame window
//
g_hwndFrame = CreateWindow(
g_szFrameWndClass,
szAppTitle,
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hinst,
NULL);
if(!g_hwndFrame)
return FALSE;
g_hwndClient = GetWindow(g_hwndFrame, GW_CHILD);
if(!g_hwndClient)
return FALSE;
// create the status bar
//
g_psb = CStatBar::Create(g_hinst, g_hwndFrame);
if(!g_psb)
return FALSE;
// initialize and show the status bar
//
g_psb->SetHeight(GetSystemMetrics(SM_CYCAPTION) - 1);
g_psb->SetFont((HFONT)GetStockObject(SYSTEM_FONT));
g_psb->SetText(OLESTR(""));
g_psb->Show();
ShowWindow(g_hwndFrame, nCmdShow);
UpdateWindow(g_hwndFrame);
return TRUE;
}
void
FrameWndOnCreate(HWND hwnd)
{
CLIENTCREATESTRUCT ccs;
ccs.hWindowMenu = NULL;
ccs.idFirstChild = IDM_FIRSTCHILD;
g_hwndClient = CreateWindow(
TSTR("MDICLIENT"),
0,
WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
0, 0, 0, 0,
hwnd,
(HMENU) 1,
g_hinst,
&ccs);
}
void
FrameWndOnSize(HWND hwnd)
{
RECT rc;
int height;
// Get the client rectangle for the frame window
GetClientRect(hwnd, &rc);
height = g_psb->GetHeight();
// adjust the client win to make room for the status bar.
//
MoveWindow(
g_hwndClient,
rc.left,
rc.top,
rc.right - rc.left,
rc.bottom - rc.top - height,
TRUE);
// move the status bar to the bottom of the newly positioned window.
//
g_psb->SetX(rc.left);
g_psb->SetY(rc.bottom - height),
g_psb->SetWidth(rc.right - rc.left);
g_psb->Move();
}
extern "C" long FAR PASCAL
FrameWndProc(
HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
switch(message){
case WM_COMMAND:
switch(wParam){
case IDM_DUMP:
CPoly::PolyDump();
return 0;
case IDM_CLEAR:
InvalidateRect(g_hwndClient, NULL, TRUE);
return 0;
}
break;
case WM_CREATE:
FrameWndOnCreate(hwnd);
break;
case WM_SIZE:
FrameWndOnSize(hwnd);
return 1;
case WM_PAINT:
CPoly::PolyDraw();
break;
case WM_CLOSE:
DestroyWindow(hwnd);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefFrameProc(hwnd, g_hwndClient, message, wParam, lParam);
}
#if defined(WIN32)
extern "C" OLECHAR FAR*
ConvertStrAtoW(char FAR* strIn, OLECHAR FAR* buf, UINT size)
{
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
strIn, -1, buf, size) ;
return buf;
}
extern "C" OLECHAR FAR*
WideString(char FAR* strIn)
{
static OLECHAR buf[256];
return (ConvertStrAtoW(strIn, buf, 256));
}
extern "C" char FAR*
ConvertStrWtoA(OLECHAR FAR* strIn, char FAR* buf, UINT size)
{
int badConversion = FALSE;
WideCharToMultiByte(CP_ACP, NULL,
strIn, -1,
buf, size,
NULL, &badConversion);
return buf;
}
extern "C" char FAR*
AnsiString(OLECHAR FAR* strIn)
{
static char buf[256];
return (ConvertStrWtoA(strIn, buf, 256));
}
#endif
|