-
Notifications
You must be signed in to change notification settings - Fork 0
/
XLOGO.C
429 lines (365 loc) · 14.8 KB
/
XLOGO.C
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
/******************* XLogo Program Source Code File (.C) ******************
*
* PROGRAM NAME: XLogo
* -------------
* Presentation Manager Standard Window C Program
*
* REVISION LEVEL: 1.0
* ---------------
*
* WHAT THIS PROGRAM DOES:
* -----------------------
*
* Display an X-Windows-style 'X', with a pop-up menu and a dialog box.
*
* WHAT THIS PROGRAM DEMONSTRATES:
* -------------------------------
* This program demonstrates how to create and display a standard window,
* and how to use resources defined in a resource script file for menus
* and dialogs.
*
* WHAT YOU NEED TO COMPILE THIS PROGRAM:
* --------------------------------------
*
* REQUIRED FILES:
* ---------------
*
* XLogo.C - Source code
* XLogo.DEF - Module definition file
* XLogo.H - Application header file
* Xpdlg.H - Dialog header file
* XLogo.ICO - Icon file
* XLogo.RC - Resource file
* Xpdlg.DLG - Dialog file
* Xpdlg.RES - Dialog resource file
*
* OS2.H - Presentation Manager include file
*
* REQUIRED LIBRARIES:
* -------------------
*
* OS2386.LIB - Presentation Manager/OS2 library
* LIBC.LIB - Protect mode/standard combined small model C library
*
* REQUIRED PROGRAMS:
* ------------------
* GCC C Compiler (shouldn't be too hard to use a different one)
* IBM Linker
* Resource Compiler
* Warp Developer's Toolkit
*
* From original HELLO sample, copyright (C) 1991 IBM Corporation
* XLogo (c) 1996 Antonino Iannella
*
* DISCLAIMER.
* The code is provided "AS IS", without
* warranty of any kind. I shall not be liable for any damages
* arising out of your use of the sample code, even if they have been
* advised of the possibility of such damages.
***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#define INCL_WIN
#define INCL_WINMENUS
#define INCL_WINWINDOWMGR
#define INCL_GPI
#define INCL_GPIPRIMITIVES
#define INCL_GPIPATHS
#include <os2.h> /* PM header file */
#include "Xlogo.h" /* Resource symbolic identifiers */
#include "Xpdlg.h" /* Dialog box header file */
#pragma linkage (ClientWndProc, system) /* For IBM ICC compiler */
/* Function prototypes */
MRESULT EXPENTRY XLogoWndProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
FNWP AboutDlgProc; /* Dialog box procedure */
/* Define parameters by type */
HAB hab; /* PM anchor block handle */
HWND hwndFrame = NULLHANDLE; /* Frame window handle */
PSZ pszErrMsg;
/**************************************************************************
*
* Name : main()
*
* Description: Initializes the process for OS/2 PM services and
* process the application message queue until a
* WM_QUIT message is received. It then destroys all
* OS/2 PM resources and terminates.
*
* Concepts : - obtains anchor block handle and creates message
* queue
* - creates the main frame window which creates the
* main client window
* - polls the message queue via Get/Dispatch Msg loop
* - upon exiting the loop, exits
*
* API's : WinInitialize
* WinCreateMsgQueue
* WinTerminate
* WinSetWindowPos
* WinSetWindowText
* WinRegisterClass
* WinCreateStdWindow
* WinGetMsg
* WinDispatchMsg
* WinDestroyWindow
* WinDestroyMsgQueue
*
* Parameters : [none]
*
* Return : 1 - if successful execution completed
* 0 - if error
*
*************************************************************************/
int main (void)
{
HMQ hmq; /* Message queue handle */
HWND hwndClient = NULLHANDLE; /* Client area window handle */
QMSG qmsg; /* Message from message queue */
ULONG flCreate; /* Window creation control flags*/
static char szClientClass[] = "XLogo.child";
if ((hab = WinInitialize(0)) == 0L) /* Initialize PM */
AbortXLogo(hwndFrame, hwndClient); /* Terminate the application */
if ((hmq = WinCreateMsgQueue( hab, 0 )) == 0L) /* Create a msg queue */
AbortXLogo(hwndFrame, hwndClient); /* Terminate the application */
if (!WinRegisterClass( /* Register window class */
hab, /* Anchor block handle */
(PSZ)szClientClass, /* Window class name */
(PFNWP)XLogoWndProc, /* Address of window procedure */
CS_SIZEREDRAW, /* Class style */
0L /* No extra window words */
))
AbortXLogo(hwndFrame, hwndClient); /* Terminate the application */
flCreate = (FCF_TITLEBAR | FCF_SYSMENU |
FCF_SIZEBORDER | FCF_MINMAX |
FCF_ACCELTABLE | FCF_ICON |
FCF_TASKLIST);
if ((hwndFrame = WinCreateStdWindow(
HWND_DESKTOP, /* Desktop window is parent */
0, /* STD. window styles */
&flCreate, /* Frame control flag */
szClientClass, /* Client window class name */
"", /* No window text */
0, /* No special class style */
(HMODULE)0L, /* Resource is in .EXE file */
ID_X, /* Frame window identifier */
&hwndClient /* Client window handle */
)) == 0L)
AbortXLogo(hwndFrame, hwndClient); /* Terminate the application */
WinSetWindowText(hwndFrame, "XLogo"); /* Sets window text */
if (!WinSetWindowPos( hwndFrame, /* Shows and activates frame */
HWND_TOP, /* window at position 100, 200, */
100, 200, 200, 200, /* and size 200, 200. */
SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_SHOW
))
AbortXLogo(hwndFrame, hwndClient); /* Terminate the application */
/* Get and dispatch messages from the application message queue */
/* until WinGetMsg returns FALSE, indicating a WM_QUIT message. */
while (WinGetMsg (hab, &qmsg, 0L, 0, 0))
WinDispatchMsg (hab, &qmsg);
WinDestroyWindow(hwndFrame); /* Tidy up... */
WinDestroyMsgQueue(hmq); /* Tidy up... */
WinTerminate(hab); /* Terminate the application */
return(0);
} /* End of main */
/**************************************************************************
*
* Name : XLogoWndProc
*
* Description: The window procedure associated with the client area in
* the standard frame window. It processes all messages
* either sent or posted to the client area, depending on
* the message command and parameters.
*
* Parameters : hwnd = window handle
* msg = message code
* mp1 = first message parameter
* mp2 = second message parameter
*
* Return : depends on message sent
*
*************************************************************************/
MRESULT EXPENTRY XLogoWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
HPS hps;
HWND hwndMenu; /* Menu resource */
RECTL rcl; /* For finding current window dimensions */
BOOL fSuccess;
switch(msg)
{
case WM_ERASEBACKGROUND:
/*
* Return TRUE to request PM to paint the window background
* in SYSCLR_WINDOW.
*/
return (MRESULT)( TRUE );
case WM_PAINT:
/*
* Window contents are drawn here in WM_PAINT processing.
*/
{
HPS hps; /* Presentation Space handle */
RECTL rc; /* Rectangle coordinates */
POINTL pt; /* String screen coordinates */
LONG Lx, Ly;
/* Starting points for paths A and B */
POINTL PathAStart,
PathBStart;
POINTL PathAPolygon[5], PathBPolygon[5]; /* Paths A, B definitions */
/* Create a presentation space */
hps = WinBeginPaint( hwnd, 0L, &rc );
GpiSetColor(hps, CLR_BLACK); /* colour of the text, */
GpiSetBackColor(hps, CLR_BACKGROUND); /* its background and */
GpiSetBackMix(hps, BM_OVERPAINT); /* how it mixes, */
/* and draw the string...*/
WinFillRect( hps, &rc, SYSCLR_WINDOW);
WinQueryWindowRect(hwnd, &rcl);
Lx = rcl.xRight - rcl.xLeft; /* Calculate window dimensions! */
Ly = rcl.yTop - rcl.yBottom;
/* Find starting points of the two paths which make up the X */
PathAStart.x = 0.061 * Lx;
PathAStart.y = Ly;
PathBStart.x = 0.864 * Lx;
PathBStart.y = Ly;
/* Find the points for path A, the left half of the X */
PathAPolygon[0].x = 0.404 * Lx;
PathAPolygon[0].y = 0.483 * Ly;
PathAPolygon[1].x = 0.06 * Lx;
PathAPolygon[1].y = 0;
PathAPolygon[2].x = 0.141 * Lx;
PathAPolygon[2].y = 0;
PathAPolygon[3].x = 0.556 * Lx;
PathAPolygon[3].y = 0.589 * Ly;
PathAPolygon[4].x = 0.288 * Lx;
PathAPolygon[4].y = Ly;
/* Find the points for path B, the right half of the X */
PathBPolygon[0].x = 0.455 * Lx;
PathBPolygon[0].y = 0.417 * Ly;
PathBPolygon[1].x = 0.722 * Lx;
PathBPolygon[1].y = 0;
PathBPolygon[2].x = 0.939 * Lx;
PathBPolygon[2].y = 0;
PathBPolygon[3].x = 0.6 * Lx;
PathBPolygon[3].y = 0.517 * Ly;
PathBPolygon[4].x = 0.939 * Lx;
PathBPolygon[4].y = Ly;
/* Define and draw path A */
GpiBeginPath(hps, 1L);
GpiMove(hps, &PathAStart);
GpiPolyLine(hps, 5L, PathAPolygon);
GpiCloseFigure(hps);
GpiEndPath(hps);
GpiFillPath(hps, 1L, FPATH_ALTERNATE);
/* Define and draw path B. Path number must be 1L */
GpiBeginPath(hps, 1L);
GpiMove(hps, &PathBStart);
GpiPolyLine(hps, 5L, PathBPolygon);
GpiCloseFigure(hps);
GpiEndPath(hps);
GpiFillPath(hps, 1L, FPATH_ALTERNATE);
WinEndPaint(hps);
break;
}
case WM_BUTTON2DOWN:
{ /* Opens the popup menu at current mouse co-ordinates */
hwndMenu = WinLoadMenu(hwnd, (HMODULE)NULL, ID_X);
fSuccess = WinPopupMenu(hwnd,
hwndFrame,
hwndMenu,
MOUSEMSG(&msg)->x,
MOUSEMSG(&msg)->y,
IDM_EXIT,
PU_POSITIONONITEM |
PU_HCONSTRAIN |
PU_VCONSTRAIN |
PU_MOUSEBUTTON2DOWN |
PU_MOUSEBUTTON2);
break;
}
case WM_CLOSE:
/*
* This is the place to put your termination routines
*/
WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );
break;
case WM_COMMAND:
switch (SHORT1FROMMP (mp1))
{
case IDM_ABOUT: /* Show Product information dialog box */
WinDlgBox(HWND_DESKTOP, hwnd, AboutDlgProc,
0, IDD_ABOUT, 0);
return ((MRESULT)0);
case IDM_EXIT:
WinSendMsg (hwnd, WM_CLOSE, 0L, 0L);
return ((MRESULT)0);
}
break;
default:
/*
* Everything else comes here. This call MUST exist
* in your window procedure.
*/
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
return (MRESULT)FALSE;
} /* End of XLogoWndProc */
/*************************************************************************/
/* Product information procedure */
/*************************************************************************/
MRESULT EXPENTRY AboutDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
switch(msg)
{
case WM_COMMAND:
switch(COMMANDMSG(&msg)->cmd)
{
case DID_OK:
WinDismissDlg(hwnd, TRUE);
return (MRESULT)TRUE;
}
break;
}
return WinDefDlgProc(hwnd, msg, mp1, mp2);
}
/**************************************************************************
*
* Name : AbortXLogo
*
* Description: Report an error returned from an API service
*
* Concepts : use of message box to display information
*
* API's : DosBeep
* WinGetErrorInfo
* WinMessageBox
* WinFreeErrorInfo
* WinPostMsg
*
* Parameters : hwndFrame = frame window handle
* hwndClient = client window handle
*
* Return : [none]
*
*************************************************************************/
VOID AbortXLogo(HWND hwndFrame, HWND hwndClient)
{
PERRINFO pErrInfoBlk;
PSZ pszOffSet;
void stdprint(void);
DosBeep(100,10);
if ((pErrInfoBlk = WinGetErrorInfo(hab)) != (PERRINFO)NULL)
{
pszOffSet = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
pszErrMsg = ((PSZ)pErrInfoBlk) + *((PSHORT)pszOffSet);
if ((INT)hwndFrame && (INT)hwndClient)
WinMessageBox(HWND_DESKTOP, /* Parent window is desktop */
hwndFrame, /* Owner window is our frame */
(PSZ)pszErrMsg, /* PMWIN Error message */
"XLogo Error Message", /* Title bar message */
MSGBOXID, /* Message identifier */
MB_MOVEABLE | MB_CUACRITICAL | MB_CANCEL );
/* Flags */
WinFreeErrorInfo(pErrInfoBlk);
}
WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
} /* End of AbortXLogo */
/************************* End of XLogo.c *********************************/