|
|
1.1 root 1: /*==============================================================*\
2: * sem_main.c - Sample PM application *
3: * Created 1990, Microsoft, IBM Corp. *
4: * *
5: * DISCLAIMER OF WARRANTIES. The following [enclosed] code is *
6: * sample code created by Microsoft Corporation and/or IBM *
7: * Corporation. This sample code is not part of any standard *
8: * Microsoft or IBM product and is provided to you solely for *
9: * the purpose of assisting you in the development of your *
10: * applications. The code is provided "AS IS", without *
11: * warranty of any kind. Neither Microsoft nor IBM shall be *
12: * liable for any damages arising out of your use of the sample*
13: * code, even if they have been advised of the possibility of *
14: * such damages. *
15: *--------------------------------------------------------------*
16: * *
17: * This application serves two distinct purposes. First, it *
18: * demonstrates the standard menus and dialogs that most PM *
19: * applications will contain. The Demo menu calls dialog *
20: * boxes that demonstrate all of the controls available for *
21: * use in a dialog box. There is also a dialog box which *
22: * demonstrates the setting and removing of control *
23: * Presentation Parameters. Finally, the demo menu also has *
24: * menu items that demonstrate the various types of message *
25: * boxes that the system supports. *
26: * *
27: * This application also serves as a template than can be *
28: * easily modified by an application developer. The source *
29: * files are organized so that the overhead code that should *
30: * be in all applications is located in the same files so *
31: * that these files do not need to be modified. The routines *
32: * that deal with application specific code are also located *
33: * in their own modules. An application developer need only *
34: * change these files in order to modify this template for *
35: * his application. *
36: * *
37: *--------------------------------------------------------------*
38: * *
39: * This source file contains the following functions: *
40: * *
41: * main() - main routine *
42: * MainWndProc(hwnd, msg, mp1, mp2) - main window procedure*
43: * MessageBox(hwnd nId, bBeep) - Warning box routine *
44: * MainCommand(mp1, mp2) - WM_COMMAND processing of Main *
45: * *
46: \*==============================================================*/
47:
48: /*--------------------------------------------------------------*\
49: * Include files, macros, defined constants, and externs *
50: \*--------------------------------------------------------------*/
51:
52: #define LINT_ARGS
53:
54: #define INCL_PM
55: #define INCL_BASE
56:
57: #include <os2.h>
58: #include <stdlib.h>
59: #include "sem_main.h"
60: #include "sem_pnt.h"
61: #include "semaph.h"
62: #include "sem_help.h"
63: #include "sem_xtrn.h"
64:
65: #define RETURN_SUCCESS 0 /* successful return in DosExit */
66: #define RETURN_ERROR 1 /* error return in DosExit */
67: #define BEEP_WARN_FREQ 60 /* frequency of warning beep */
68: #define BEEP_WARN_DUR 100 /* duration of warning beep */
69: #define MAXWIDTH 80 /* for now */
70: #define NUMLINES 25 /* for now */
71:
72: /*--------------------------------------------------------------*\
73: * Global variables *
74: \*--------------------------------------------------------------*/
75: HWND hwndMainFrame; /* handle to the main frame window */
76: HWND hwndMain; /* handle to the main client window */
77: HAB hab; /* anchor block for the process */
78: HMQ hmq; /* handle to the process' message queue */
79: CHAR szAppName[MAXAPPNAMELEN]; /* buffer for application name string */
80:
81: /*--------------------------------------------------------------*\
82: * Entry point declarations *
83: \*--------------------------------------------------------------*/
84:
85: /****************************************************************\
86: * Main routine *
87: *--------------------------------------------------------------*
88: * *
89: * Name: main() *
90: * *
91: * Purpose: Initializes the PM environment, calls the *
92: * initialization routine, creates the main *
93: * window, and polls the message queue *
94: * *
95: * Usage: *
96: * *
97: * Method: *
98: * - obtains anchor block handle and creates message *
99: * queue *
100: * - calls the initialization routine *
101: * - creates the main frame window which creates the *
102: * main client window *
103: * - polls the message queue via Get/Dispatch Msg loop *
104: * - upon exiting the loop, exits *
105: * *
106: * Returns: (via DosExit) *
107: * 1 - if sucessful execution completed *
108: * 0 - if error *
109: \****************************************************************/
110:
111: VOID cdecl main(VOID)
112: {
113: QMSG qmsg; /* message structure */
114: ULONG ctlData; /* frame control data */
115:
116: hab = WinInitialize(0);
117: if(!hab) {
118: DosBeep(BEEP_WARN_FREQ, BEEP_WARN_DUR);
119: DosExit(EXIT_PROCESS, RETURN_ERROR);
120: }
121: /* find a define for this v */
122: hmq = WinCreateMsgQueue(hab, 0);
123: if(!hmq) {
124: DosBeep(BEEP_WARN_FREQ, BEEP_WARN_DUR);
125: WinTerminate(hab);
126: DosExit(EXIT_PROCESS, RETURN_ERROR);
127: }
128:
129: if(!Init()) {
130: MessageBox(HWND_DESKTOP, IDMSG_INITFAILED, TRUE);
131: DosExit(EXIT_PROCESS, RETURN_ERROR);
132: }
133:
134: /* create the main window */
135:
136: ctlData = FCF_STANDARD & ~FCF_ACCELTABLE;
137:
138: hwndMainFrame = WinCreateStdWindow(HWND_DESKTOP,
139: WS_VISIBLE,
140: (PVOID)&ctlData,
141: (PSZ)szAppName,
142: (PSZ)NULL,
143: WS_VISIBLE,
144: (HMODULE)NULL,
145: IDR_SAMPLE,
146: (PHWND)&hwndMain);
147:
148: if(!hwndMainFrame) {
149: MessageBox(HWND_DESKTOP, IDMSG_MAINWINCREATEFAILED, TRUE);
150: DosExit(EXIT_PROCESS, RETURN_ERROR);
151: }
152:
153: while(WinGetMsg(hmq, (PQMSG)&qmsg, NULL, NULL, NULL))
154: WinDispatchMsg(hmq, (PQMSG)&qmsg);
155:
156: DosExit(EXIT_PROCESS, RETURN_SUCCESS);
157:
158: } /* main() */
159:
160:
161: /****************************************************************\
162: * Main client window procedure *
163: *--------------------------------------------------------------*
164: * *
165: * Name: MainWndProc(hwnd, msg, mp1, mp2) *
166: * *
167: * Purpose: Processes the messages sent to the main client *
168: * window. This routine processes the basic *
169: * messages all client windows should process *
170: * and passes all others onto UserWndProc where *
171: * the developer can process any others. *
172: * *
173: * Usage: Called for each message placed in the main *
174: * window's message queue *
175: * *
176: * Method: a switch statement branches to the routines to be *
177: * performed for each message processed. Any messages *
178: * not specifically process are passed to the user's *
179: * message processing procedure UserWndProc(). *
180: * *
181: * Returns: Return values are determined by each message *
182: * *
183: \****************************************************************/
184:
185: MRESULT EXPENTRY MainWndProc(hwnd, msg, mp1, mp2)
186: HWND hwnd; /* handle of window */
187: USHORT msg; /* id of message */
188: MPARAM mp1; /* first message parameter */
189: MPARAM mp2; /* second message parameter */
190: {
191: FONTMETRICS fntmet;
192: HPS hPS;
193: static SHORT xClient, yClient;
194: static SHORT yChar, yDesc;
195:
196: switch(msg) {
197: case WM_CREATE:
198: hPS = WinGetPS (hwnd);
199: GpiQueryFontMetrics (hPS, (LONG) sizeof fntmet, &fntmet);
200:
201: yChar = (SHORT) fntmet.lMaxBaselineExt;
202: yDesc = (SHORT) fntmet.lMaxDescender;
203:
204: WinReleasePS (hPS);
205: break;
206:
207: case WM_PAINT:
208: MainPaint(hwnd);
209: break;
210:
211: case WM_SIZE:
212: xClient = LOUSHORT (mp2); /* width of window */
213: yClient = HIUSHORT (mp2); /* height of window */
214: /* fall thru to ... */
215: case WM_USERCHANGED: /* number of threads changed */
216: /* so x and y are already known */
217: SetRectPositions(xClient, yClient, yChar, yDesc);
218: WinInvalidateRect (hwnd, NULL, TRUE);
219: break;
220:
221: case WM_COMMAND:
222: MainCommand(mp1, mp2);
223: break;
224:
225: case HM_QUERY_KEYS_HELP:
226: return (MRESULT)PANEL_HELPKEYS; /* return id of key help panel */
227: break;
228:
229: /*--------------------------------------------------*\
230: * Any messages not processed are passed on *
231: * to the user's window proc. It is *
232: * responsible for passing any messages it *
233: * doesn't handle onto WinDefWindowProc() *
234: \*--------------------------------------------------*/
235: default:
236: return(UserWndProc(hwnd, msg, mp1, mp2));
237: break;
238:
239: }
240: return 0L; /* all window procedures should return 0 as a default */
241:
242: } /* MainWndProc() */
243:
244: /****************************************************************\
245: * Message Box procedure *
246: *--------------------------------------------------------------*
247: * *
248: * Name: MessageBox(hwndOwner, nIdMsg, bBeep) *
249: * *
250: * Purpose: Displays the warning message box with the message *
251: * given in nIdMsg retrived from the message table *
252: * *
253: * Usage: Called whever an error occurs and a message wishes *
254: * to be displayed to the user *
255: * *
256: * Method: - Message string is loaded from the process' *
257: * message table *
258: * - Alarm beep is sounded if desired *
259: * - Message box with the message is displayed *
260: * *
261: * Returns: *
262: * *
263: \****************************************************************/
264:
265: VOID MessageBox(hwndOwner, nIdMsg, bBeep)
266: HWND hwndOwner; /* handle of the message box's owner */
267: SHORT nIdMsg; /* id if the message in the message table */
268: BOOL bBeep; /* if TRUE, beep before message box is displayed */
269: {
270: CHAR szText[MESSAGELEN];
271:
272: if(!WinLoadMessage(hab, (HMODULE)NULL, nIdMsg, MESSAGELEN, (PSZ)szText)) {
273: WinAlarm(HWND_DESKTOP, WA_ERROR);
274: return;
275: }
276:
277: if(bBeep)
278: WinAlarm(HWND_DESKTOP, WA_ERROR);
279:
280: WinMessageBox(HWND_DESKTOP,
281: hwndOwner,
282: szText,
283: (PSZ)NULL,
284: 1,
285: MB_OK | MB_ERROR);
286:
287: } /* MessageBox() */
288:
289: /****************************************************************\
290: * Main window WM_COMMAND processing procedure *
291: *--------------------------------------------------------------*
292: * *
293: * Name: MainCommand(mp1, mp2) *
294: * *
295: * Purpose: Calls the appropriate procedures that deal with *
296: * the selected menu item. *
297: * *
298: * Usage: Routine is called whenever a WM_COMMAND message *
299: * is posted to the main window. *
300: * *
301: * Method: a switch statement branches on the id of the *
302: * menu item that posted the message and the *
303: * appropriate action for that item is taken. Any *
304: * menu ids that are not part of the standard menu *
305: * set are passed onto the user defined WM_COMMAND *
306: * processing procedure. *
307: * *
308: * Returns: *
309: * *
310: \****************************************************************/
311: VOID MainCommand(mp1, mp2)
312: MPARAM mp1; /* first parameter of WM_COMMAND message */
313: MPARAM mp2; /* second parameter of WM_COMMAND message */
314: {
315:
316: switch(SHORT1FROMMP(mp1)) {
317:
318: #ifdef LATER
319: case IDM_FILENEW:
320: FileNew(mp2);
321: break;
322:
323: case IDM_FILEOPEN:
324: FileOpen(mp2);
325: break;
326:
327: case IDM_FILESAVE:
328: FileSave(mp2);
329: break;
330:
331: case IDM_FILESAVEAS:
332: FileSaveAs(mp2);
333: break;
334:
335: case IDM_EDITUNDO:
336: EditUndo(mp2);
337: break;
338:
339: case IDM_EDITCUT:
340: EditCut(mp2);
341: break;
342:
343: case IDM_EDITCOPY:
344: EditCopy(mp2);
345: break;
346:
347: case IDM_EDITPASTE:
348: EditPaste(mp2);
349: break;
350:
351: case IDM_EDITCLEAR:
352: EditClear(mp2);
353: break;
354:
355: case IDM_WINDOWTILE:
356: WindowTile(mp2);
357: break;
358:
359: case IDM_WINDOWCASCADE:
360: WindowCascade(mp2);
361: break;
362:
363: case IDM_HELPFORHELP:
364: HelpHelpForHelp(mp2);
365: break;
366:
367: case IDM_HELPEXTENDED:
368: HelpExtended(mp2);
369: break;
370:
371: case IDM_HELPKEYS:
372: HelpKeys(mp2);
373: break;
374:
375: case IDM_HELPINDEX:
376: HelpIndex(mp2);
377: break;
378:
379: case IDM_HELPTUTORIAL:
380: HelpTutorial(mp2);
381: break;
382:
383: case IDM_FILEPRINT:
384: FilePrint(mp2);
385: break;
386:
387: case IDM_FILEPAGESETUP:
388: FilePageSetup(mp2);
389: break;
390:
391: case IDM_FILEPRINTSETUP:
392: FilePrintSetup(mp2);
393: break;
394:
395: case IDM_HELPHELPFORHELP:
396: HelpHelpForHelp(mp2);
397: break;
398:
399: #endif
400:
401: case IDM_HELPABOUT:
402: HelpAbout(mp2);
403: break;
404:
405: case IDM_FILEEXIT:
406: FileExit(mp2);
407: break;
408:
409:
410: /*--------------------------------------------------*\
411: * User command processing routine is called *
412: * here so any ids not procecessed here can be *
413: * processed *
414: \*--------------------------------------------------*/
415: default:
416: UserCommand(mp1, mp2);
417: break;
418: }
419:
420: } /* MainCommand() */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.