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