|
|
1.1 root 1: /*==============================================================*\
2: * sem_init.c - routines for initialization and exit processing *
3: * Created 1990, Microsoft, IBM Corp. *
4: *--------------------------------------------------------------*
5: * *
6: * This module contains the code for application initialization*
7: * as well as the code for exit list processing *
8: * *
9: *--------------------------------------------------------------*
10: * *
11: * This source file contains the following functions: *
12: * *
13: * Init() - initialization routines *
14: * ExitProc(usTermCode) - exit list processing procedure *
15: * *
16: \*==============================================================*/
17:
18: /*--------------------------------------------------------------*\
19: * Include files, macros, defined constants, and externs *
20: \*--------------------------------------------------------------*/
21:
22: #define LINT_ARGS
23:
24: #define INCL_WIN
25: #define INCL_DOSPROCESS
26: #include <os2.h>
27: #include <string.h>
28: #include "sem_main.h"
29: #include "sem_xtrn.h"
30: /*--------------------------------------------------------------*\
31: * Global variables *
32: \*--------------------------------------------------------------*/
33:
34: /*--------------------------------------------------------------*\
35: * Entry point declarations *
36: \*--------------------------------------------------------------*/
37:
38: /****************************************************************\
39: * Initialization routine *
40: *--------------------------------------------------------------*
41: * *
42: * Name: Init() *
43: * *
44: * Purpose: Performs initialization functions required *
45: * before the main window can be created. *
46: * *
47: * Usage: Called once before the main window is created. *
48: * *
49: * Method: *
50: * - installs the routine ExitProc into the *
51: * DosExitList chain *
52: * - registers all window classes *
53: * - performs any command line processing *
54: * *
55: * Returns: *
56: * TRUE - initialization is successful *
57: * FALSE - initialization failed *
58: \****************************************************************/
59:
60: BOOL Init(VOID)
61: {
62: /* Add ExitProc to the exit list to handle the exit processing */
63: if(DosExitList(EXLST_ADD, (PFNEXITLIST)ExitProc)) {
64: return FALSE;
65: }
66:
67: /* load application name from resource file */
68: if(!WinLoadString(hab, NULL, IDS_APPNAME, MAXAPPNAMELEN, szAppName))
69: return FALSE;
70:
71: /* register the main client window class */
72: if(!WinRegisterClass(hab,
73: (PSZ)szAppName,
74: (PFNWP)MainWndProc,
75: CS_SIZEREDRAW | CS_SYNCPAINT | CS_CLIPCHILDREN,
76: 0)) {
77: return FALSE;
78: }
79:
80: /* initialize data structures */
81: InitSemaphExample ();
82: /*--------------------------------------------------*\
83: * Add any command line processing here *
84: \*--------------------------------------------------*/
85:
86:
87: return TRUE;
88:
89: } /* Init() */
90:
91:
92:
93: /****************************************************************\
94: * Exit list processing procedure *
95: *--------------------------------------------------------------*
96: * *
97: * Name: ExitProc(usTermCode) *
98: * *
99: * Purpose: Cleans up certain resources when the application *
100: * terminates *
101: * *
102: * Usage: Routine is called by DosExitList when the *
103: * application exits *
104: * *
105: * Method: global resources, such as the main window and *
106: * message queue, are destroyed and any system *
107: * resources used are freed *
108: * *
109: * Returns: Returns EXLST_EXIT to the DosExitList handler *
110: * *
111: \****************************************************************/
112:
113: VOID PASCAL FAR ExitProc(usTermCode)
114: USHORT usTermCode; /* code for the reason for termination */
115: {
116:
117: WinDestroyWindow(hwndMainFrame);
118:
119: /*--------------------------------------------------*\
120: * Any other system resources used *
121: * (e.g. memory or files) should be freed here *
122: \*--------------------------------------------------*/
123:
124: WinDestroyMsgQueue(hmq);
125:
126: WinTerminate(hab);
127:
128: DosExitList(EXLST_EXIT, 0L); /* termination complete */
129:
130: /* This routine currently doesn't use the usTermCode parameter so *\
131: * it is referenced here to prevent an 'Unreferenced Parameter' *
132: \* warning at compile time */
133:
134: usTermCode;
135:
136: } /* ExitProc() */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.