|
|
1.1 root 1: /*==============================================================*\
2: * Main.c - Sample PM application main source file
3: *
4: * Created 1989, 1990 Microsoft 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 as a template than can be
20: * easily modified by an application developer. The source
21: * files are organized so that the overhead code that should
22: * be in all applications is located in the same files so
23: * that these files do not need to be modified. The routines
24: * that deal with application specific code are also located
25: * in their own modules. An application developer need only
26: * change these files in order to modify this template for
27: * his application.
28: *
29: *--------------------------------------------------------------
30: *
31: * This source file contains the following functions:
32: *
33: * main() - main routine
34: * MainWndProc(hwnd, msg, mp1, mp2) - main window procedure
35: * MessageBox(hwnd idMsg, fsStyle, fBeep) - Message box routine
36: * MainCommand(mp1, mp2) - WM_COMMAND processing of Main
37: *
38: \*==============================================================*/
39:
40: /*--------------------------------------------------------------*\
41: * Include files, macros, defined constants, and externs
42: \*--------------------------------------------------------------*/
43:
44: #define INCL_WINHELP
45:
46: #include <os2.h>
47: #include "main.h"
48: #include "help.h"
49: #include "xtrn.h"
50:
51:
52: /*----
53: * Define these constants when th corresponding components (Help manager,
54: * etc.) are implimented in the product
55: *---
56: /* #define PRINT_DLGS_ENABLED */
57:
58:
59: /*--------------------------------------------------------------*\
60: * Global variables
61: \*--------------------------------------------------------------*/
62: HWND hwndMainFrame = NULL; /* handle to the main frame window */
63: HWND hwndMain; /* handle to the main client window */
64: HDC hdcMain; /* handle to the DC of the client */
65: HAB hab; /* anchor block for the process */
66: HMQ hmq; /* handle to the process' message queue */
67: CHAR szAppName[MAXNAMEL]; /* buffer for application name string */
68: CHAR szUntitled[MESSAGELEN]; /* buffer for "Untitled" string */
69: BOOL fPrintEnabled; /* flag to determine if we can print */
70: BOOL fHelpEnabled; /* flag to determine if help is enabled */
71:
72: /*--------------------------------------------------------------*\
73: * Entry point declarations
74: \*--------------------------------------------------------------*/
75:
76: /****************************************************************\
77: * Main routine
78: *--------------------------------------------------------------
79: *
80: * Name: main()
81: *
82: * Purpose: Initializes the PM environment, calls the
83: * initialization routine, creates the main
84: * window, and polls the message queue
85: *
86: * Usage:
87: *
88: * Method:
89: * - obtains anchor block handle and creates message
90: * queue
91: * - calls the initialization routine
92: * - creates the main frame window which creates the
93: * main client window
94: * - polls the message queue via Get/Dispatch Msg loop
95: * - upon exiting the loop, exits
96: *
97: * Returns:
98: * 1 - if sucessful execution completed
99: * 0 - if error
100: \****************************************************************/
101: BOOL cdecl main(VOID)
102: {
103: QMSG qmsg; /* message structure */
104: ULONG flCtlData; /* frame control data */
105:
106: hab = WinInitialize(0);
107:
108: if(!hab) {
109: DosBeep(BEEP_WARN_FREQ, BEEP_WARN_DUR);
110: return(RETURN_ERROR);
111: }
112:
113: hmq = WinCreateMsgQueue(hab, 0);
114:
115: if(!hmq) {
116: DosBeep(BEEP_WARN_FREQ, BEEP_WARN_DUR);
117: WinTerminate(hab);
118: return(RETURN_ERROR);
119: }
120:
121: if(!Init()) {
122: MessageBox(HWND_DESKTOP,
123: IDMSG_INITFAILED,
124: MB_OK | MB_ERROR,
125: TRUE);
126:
127: return(RETURN_ERROR);
128: }
129:
130: /* NOTE: clean up from here is handled by the DosExitList processing */
131:
132:
133: /* create the main window */
134: flCtlData = FCF_STANDARD;
135:
136: hwndMainFrame = WinCreateStdWindow(HWND_DESKTOP,
137: WS_VISIBLE,
138: (PULONG)&flCtlData,
139: (PSZ)szAppName,
140: (PSZ)NULL,
141: WS_VISIBLE,
142: (HMODULE)NULL,
143: IDR_MAIN,
144: (PHWND)&hwndMain);
145:
146: if(hwndMainFrame == NULL) {
147: MessageBox(HWND_DESKTOP,
148: IDMSG_MAINWINCREATEFAILED,
149: MB_OK | MB_ERROR,
150: TRUE);
151: return(RETURN_ERROR);
152: }
153:
154: hdcMain = WinOpenWindowDC(hwndMain);
155:
156: InitHelp();
157:
158: /* Get/Dispatch Message loop */
159: while(WinGetMsg(hmq, (PQMSG)&qmsg, NULL, NULL, NULL))
160: WinDispatchMsg(hmq, (PQMSG)&qmsg);
161:
162: /* destroy the help instance */
163: DestroyHelpInstance();
164:
165: #ifdef BACKGROUND_THREAD
166: /* see main.h for comment on using a background thread */
167: DestroyBackgroundThread();
168: #endif
169:
170:
171: return(RETURN_SUCCESS);
172:
173: } /* main() */
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: case TM_THREADINITFAILED:
228: /* message is received if the background thread initialization
229: fails. A message box is displayed and the application is
230: terminated */
231: MessageBox(HWND_DESKTOP,
232: IDMSG_INITFAILED,
233: MB_OK | MB_ERROR,
234: TRUE);
235:
236: WinPostMsg(hwnd, WM_CLOSE, NULL, NULL);
237: break;
238:
239: /*--------------------------------------------------*\
240: * Any messages not processed are passed on
241: * to the user's window proc. It is
242: * responsible for passing any messages it
243: * doesn't handle onto WinDefWindowProc()
244: \*--------------------------------------------------*/
245:
246: default:
247: return(UserWndProc(hwnd, msg, mp1, mp2));
248: break;
249:
250: }
251: return 0L; /* all window procedures should return 0 as a default */
252:
253: } /* MainWndProc() */
254:
255: /****************************************************************\
256: * Message Box procedure
257: *--------------------------------------------------------------
258: *
259: * Name: MessageBox(hwndOwner, nIdMsg, fsStyle, fBeep)
260: *
261: * Purpose: Displays the message box with the message
262: * given in idMsg retrieved from the message table
263: * and using the style flags in fsStyle
264: *
265: * Usage: Called whenever a MessageBox is to be displayed
266: *
267: * Method: - Message string is loaded from the process'
268: * message table
269: * - Alarm beep is sounded if desired
270: * - Message box with the message is displayed
271: * - WinMessageBox return value is returned
272: *
273: * Returns: return value from WinMessageBox()
274: *
275: \****************************************************************/
276: SHORT MessageBox(hwndOwner, idMsg, fsStyle, fBeep)
277: HWND hwndOwner; /* handle of the message box's owner */
278: SHORT idMsg; /* id if the message in the message table */
279: SHORT fsStyle; /* style of the message box */
280: BOOL fBeep; /* if TRUE, beep before message box is displayed */
281: {
282: CHAR szText[MESSAGELEN];
283:
284: if(!WinLoadMessage(hab,
285: (HMODULE)NULL,
286: idMsg,
287: MESSAGELEN,
288: (PSZ)szText)) {
289:
290: WinAlarm(HWND_DESKTOP, WA_ERROR);
291: return MBID_ERROR;
292: }
293:
294: if(fBeep) {
295: WinAlarm(HWND_DESKTOP, WA_ERROR);
296: }
297:
298: return(WinMessageBox(HWND_DESKTOP,
299: hwndOwner,
300: szText,
301: (PSZ)NULL,
302: MSGBOXID,
303: fsStyle));
304:
305: } /* MessageBox() */
306:
307: /****************************************************************\
308: * Main window WM_COMMAND processing procedure
309: *--------------------------------------------------------------
310: *
311: * Name: MainCommand(mp1, mp2)
312: *
313: * Purpose: Calls the appropriate procedures that deal with
314: * the selected menu item.
315: *
316: * Usage: Routine is called whenever a WM_COMMAND message
317: * is posted to the main window.
318: *
319: * Method: a switch statement branches on the id of the
320: * menu item that posted the message and the
321: * appropriate action for that item is taken. Any
322: * menu ids that are not part of the standard menu
323: * set are passed onto the user defined WM_COMMAND
324: * processing procedure.
325: *
326: * Returns:
327: *
328: \****************************************************************/
329: VOID MainCommand(mp1, mp2)
330: MPARAM mp1; /* first parameter of WM_COMMAND message */
331: MPARAM mp2; /* second parameter of WM_COMMAND message */
332: {
333:
334: switch(SHORT1FROMMP(mp1)) {
335:
336: case IDM_FILENEW:
337: FileNew(mp2);
338: break;
339:
340: case IDM_FILEOPEN:
341: FileOpen(mp2);
342: break;
343:
344: case IDM_FILESAVE:
345: FileSave(mp2);
346: break;
347:
348: case IDM_FILESAVEAS:
349: FileSaveAs(mp2);
350: break;
351:
352: #ifdef PRINT_DIALOGS_ENABLED
353:
354: case IDM_FILEPRINT:
355: FilePrint(mp2);
356: break;
357:
358: case IDM_FILEPAGESETUP:
359: FilePageSetup(mp2);
360: break;
361:
362: case IDM_FILEPRINTSETUP:
363: FilePrintSetup(mp2);
364: break;
365:
366: #endif /* PRINT_DLGS_ENABLED */
367:
368: case IDM_FILEEXIT:
369: FileExit(mp2);
370: break;
371:
372: case IDM_EDITUNDO:
373: EditUndo(mp2);
374: break;
375:
376: case IDM_EDITCUT:
377: EditCut(mp2);
378: break;
379:
380: case IDM_EDITCOPY:
381: EditCopy(mp2);
382: break;
383:
384: case IDM_EDITPASTE:
385: EditPaste(mp2);
386: break;
387:
388: case IDM_EDITCLEAR:
389: EditClear(mp2);
390: break;
391:
392: case IDM_HELPHELPFORHELP:
393: HelpHelpForHelp(mp2);
394: break;
395:
396: case IDM_HELPEXTENDED:
397: HelpExtended(mp2);
398: break;
399:
400: case IDM_HELPKEYS:
401: HelpKeys(mp2);
402: break;
403:
404: case IDM_HELPINDEX:
405: HelpIndex(mp2);
406: break;
407:
408: case IDM_HELPTUTORIAL:
409: HelpTutorial(mp2);
410: break;
411:
412: case IDM_HELPABOUT:
413: HelpAbout(mp2);
414: break;
415:
416:
417:
418: /*--------------------------------------------------*\
419: * User command processing routine is called
420: * here so any ids not processed here can be
421: * processed
422: \*--------------------------------------------------*/
423: default:
424: UserCommand(mp1, mp2);
425: break;
426: }
427:
428: } /* MainCommand() */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.