-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.c
232 lines (198 loc) · 7.07 KB
/
init.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
/**************************************************************************
* File name : init.c
*
* Description: This module contains the code for application
* initialization, as well as the code for exit list
* processing
*
* This source file contains the following functions:
*
* Init()
* InitMainWindow(hwnd, mp1, mp2)
* ExitProc(usTermCode)
*
* Concepts : initialization
*
* API's : DosExitList
* DosExit
* WinLoadString
* WinRegisterClass
* WinIsWindow
* WinDestroyWindow
* WinDestroyMsgQueue
* WinTerminate
*
* Required
* Files : OS2.H, STRING.H, MAIN.H, XTRN.H
*
* Copyright (C) 1991 IBM Corporation
*
* DISCLAIMER OF WARRANTIES. The following [enclosed] code is
* sample code created by IBM Corporation. This sample code is not
* part of any standard or IBM product and is provided to you solely
* for the purpose of assisting you in the development of your
* applications. The code is provided "AS IS", without
* warranty of any kind. IBM 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 files, macros, defined constants, and externs
*/
#define INCL_WINWINDOWMGR
#define INCL_DOSPROCESS
#include <os2.h>
#include <string.h>
#include "main.h"
#include "xtrn.h"
/*
* Global variables
*/
/*
* Entry point declarations
*/
/**************************************************************************
*
* Name : Init()
*
* Description: Performs initialization functions required
* before the main window can be created.
*
* Concepts: Called once before the main window is created.
*
* - Installs the routine ExitProc into the
* DosExitList chain
* - registers all window classes
* - performs any command line processing
*
* API's : DosExitList
* DosExit
* WinLoadString
* WinRegisterClass
*
* Parameters : [none]
*
* Return : TRUE = initialization is successful
* FALSE = initialization failed
*
*************************************************************************/
BOOL Init(VOID)
{
/* Add ExitProc to the exit list to handle the exit processing. If
* there is an error, then terminate the process since there have
* not been any resources allocated yet.
*/
if(DosExitList(EXLST_ADD, (PFNEXITLIST)ExitProc))
{
MessageBox(HWND_DESKTOP,
IDMSG_CANNOTLOADEXITLIST,
MB_OK | MB_ERROR,
TRUE);
DosExit(EXIT_PROCESS, RETURN_ERROR);
}
/* load application name from resource file */
if(0 == WinLoadString(hab, (HMODULE)0, IDS_APPNAME, MAXNAMEL, (PSZ) szAppName))
return FALSE;
/* load "untitled" string */
if(!WinLoadString(hab, (HMODULE)0, IDS_UNTITLED, MESSAGELEN, (PSZ) szUntitled))
return FALSE;
/* register the main client window class */
if(!WinRegisterClass(hab,
(PSZ)szAppName,
(PFNWP)MainWndProc,
CS_SIZEREDRAW | CS_CLIPCHILDREN,
0L))
return FALSE;
/* If you wish to create a thread for background processing, define
* the BACKGROUND_THREAD constant
* the routine commented out here. The routines for the background
* thread are in the thrd.c file.
*/
#ifdef BACKGROUND_THREAD
/* see main.h for comment on using a background thread */
if(!CreateBackgroundThread())
return FALSE;
#endif
/*
* Add any command line processing here.
*/
return TRUE;
} /* End of Init */
/**************************************************************************
*
* Name : InitMainWindow(hwnd, mp1, mp2)
*
* Description: Performs initialization functions required
* when the main window is created.
*
* Concepts: Called once during the WM_CREATE processing when
* the main window is created.
*
* API's : [none]
*
* Parameters : hwnd = window handle
* mp1 = first message parameter
* mp2 = second message parameter
*
* Return : value to be returned from the WM_CREATE message:
* TRUE = window creation should stop
* FALSE = window creation should continue
*
*************************************************************************/
MRESULT InitMainWindow(HWND hwnd, MPARAM mp1, MPARAM mp2)
{
UpdateTitleText(((PCREATESTRUCT)PVOIDFROMMP(mp2))->hwndParent);
/* return FALSE to continue window creation, TRUE to abort it */
return (MRESULT)FALSE;
/* This routine currently doesn't use the hwnd, mp1, and mp2 parameters
* so they are referenced here to prevent an 'Unreferenced Parameter'
* warning at compile time.
*/
// hwnd; // Removed. Gcc said: warning: statement with no effect [-Wunused-value]
// mp1; // Removed. Gcc said: warning: statement with no effect [-Wunused-value]
// mp2; // Removed. Gcc said: warning: statement with no effect [-Wunused-value]
} /* End of InitMainWindow */
/**************************************************************************
*
* Name : ExitProc(usTermCode)
*
* Description: Cleans up certain resources when the application
* terminates.
*
* Concepts: Routine is called by DosExitList when the
* application exits.
*
* Global resources, such as the main window and
* message queue, are destroyed and any system
* resources used are freed.
*
* API's : WinIsWindow
* WinDestroyWindow
* WinDestroyMsgQueue
* WinTerminate
* DosExitList
*
* Parameters : usTermCode = termination code number
*
* Return : Returns EXLST_EXIT to the DosExitList handler
*
*************************************************************************/
VOID ExitProc(USHORT usTermCode)
{
/* destroy the main window if it exists */
if(WinIsWindow(hab, hwndMainFrame))
WinDestroyWindow(hwndMainFrame);
/*
* Any other system resources used
* (e.g. memory or files) should be freed here.
*/
WinDestroyMsgQueue(hmq);
WinTerminate(hab);
DosExitList(EXLST_EXIT, (PFNEXITLIST)NULL); /* termination complete */
/* This routine currently doesn't use the usTermCode parameter so
* it is referenced here to prevent an 'Unreferenced Parameter'
* warning at compile time
*/
//usTermCode; // Removed. Gcc said: warning: statement with no effect [-Wunused-value]
} /* End of ExitProc */
/*************************** End of init.c ***************************/