|
|
1.1 root 1:
2: /******************************************************************************\
3: * This is a part of the Microsoft Source Code Samples.
4: * Copyright (C) 1993 Microsoft Corporation.
5: * All rights reserved.
6: * This source code is only intended as a supplement to
7: * Microsoft Development Tools and/or WinHelp documentation.
8: * See these sources for detailed information regarding the
9: * Microsoft samples programs.
10: \******************************************************************************/
11:
12: /****************************************************************************
13:
14: PROGRAM: Platform.c
15:
16: PURPOSE: Platform template for Windows applications
17:
18: FUNCTIONS:
19:
20: WinMain() - calls initialization function, processes message loop
21: InitApplication() - initializes window data and registers window
22: InitInstance() - saves instance handle and creates main window
23: MainWndProc() - processes messages
24: About() - processes messages for "About" dialog box
25:
26: COMMENTS:
27:
28: Windows can have several copies of your application running at the
29: same time. The variable hInst keeps track of which instance this
30: application is so that processing will be to the correct window.
31:
32: ****************************************************************************/
33:
34: #define STRICT
35:
36:
37: #include <stddef.h>
38: #include "windows.h" /* required for all Windows applications */
39:
40: #if defined(_WIN32)
41: #define WIN32S 0x80000000l // no manifest constance yet???
42: #else
43: #define APIENTRY FAR PASCAL
44: #define WINAPI FAR PASCAL
45: #define TCHAR char
46: #define LPTSTR LPSTR
47: #define UNREFERENCED_PARAMETER(x) x;
48: #define TEXT(x) x
49:
50: #define WF1_WINNT 0x40 /* A special version of GetWinFlags() will
51: * be provide in the WOW Layer which returns
52: * a MANEFEST CONSTANT signifing to Win16
53: * apps that it's running in WOW instead of
54: * DOS/Windows. Unfortunately this value
55: * was not specified at the time of this
56: * sample. As *soon* as Development has set
57: * on a manifest contanst PSS will upload a
58: * KnowledgeBase article. Describing this flag
59: * and any other relevent details need to get
60: * this sample correctly identifing what platform
61: * it's running on.
62: */
63:
64: #endif
65:
66:
67: #include "Platform.h" /* specific to this program */
68:
69:
70: HINSTANCE hInst; /* current instance */
71:
72:
73: /****************************************************************************
74:
75: FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
76:
77: PURPOSE: calls initialization function, processes message loop
78:
79: COMMENTS:
80:
81: Windows recognizes this function by name as the initial entry point
82: for the program. This function calls the application initialization
83: routine, if no other instance of the program is running, and always
84: calls the instance initialization routine. It then executes a message
85: retrieval and dispatch loop that is the top-level control structure
86: for the remainder of execution. The loop is terminated when a WM_QUIT
87: message is received, at which time this function exits the application
88: instance by returning the value passed by PostQuitMessage().
89:
90: If this function must abort before entering the message loop, it
91: returns the conventional value NULL.
92:
93: ****************************************************************************/
94:
95: int WINAPI WinMain(HINSTANCE hInstance, /* current instance */
96: HINSTANCE hPrevInstance, /* previous instance */
97: LPSTR lpCmdLine, /* command line */
98: int nCmdShow) /* show-window type (open/icon) */
99: {
100: MSG msg; /* message */
101:
102: if (!hPrevInstance) /* Other instances of app running? */
103: if (!InitApplication(hInstance)) /* Initialize shared things */
104: return (FALSE); /* Exits if unable to initialize */
105:
106: /* Perform initializations that apply to a specific instance */
107:
108: if (!InitInstance(hInstance, nCmdShow))
109: return (FALSE);
110:
111: /* Acquire and dispatch messages until a WM_QUIT message is received. */
112:
113: while (GetMessage(&msg, /* message structure */
114: NULL, /* handle of window receiving the message */
115: 0, /* lowest message to examine */
116: 0)) /* highest message to examine */
117: {
118: TranslateMessage(&msg); /* Translates virtual key codes */
119: DispatchMessage(&msg); /* Dispatches message to window */
120: }
121:
122: return (msg.wParam); /* Returns the value from PostQuitMessage */
123: UNREFERENCED_PARAMETER(lpCmdLine);
124: }
125:
126:
127: /****************************************************************************
128:
129: FUNCTION: InitApplication(HANDLE)
130:
131: PURPOSE: Initializes window data and registers window class
132:
133: COMMENTS:
134:
135: This function is called at initialization time only if no other
136: instances of the application are running. This function performs
137: initialization tasks that can be done once for any number of running
138: instances.
139:
140: In this case, we initialize a window class by filling out a data
141: structure of type WNDCLASS and calling the Windows RegisterClass()
142: function. Since all instances of this application use the same window
143: class, we only need to do this when the first instance is initialized.
144:
145:
146: ****************************************************************************/
147:
148: BOOL InitApplication(HANDLE hInstance) /* current instance */
149: {
150: WNDCLASS wc;
151:
152: /* Fill in window class structure with parameters that describe the */
153: /* main window. */
154:
155: wc.style = 0; /* Class style(s). */
156: wc.lpfnWndProc = (WNDPROC)MainWndProc; /* Function to retrieve messages for */
157: /* windows of this class. */
158: wc.cbClsExtra = 0; /* No per-class extra data. */
159: wc.cbWndExtra = 0; /* No per-window extra data. */
160: wc.hInstance = hInstance; /* Application that owns the class. */
161: wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
162: wc.hCursor = LoadCursor(NULL, IDC_ARROW);
163: wc.hbrBackground = GetStockObject(WHITE_BRUSH);
164: wc.lpszMenuName = "PlatformMenu"; /* Name of menu resource in .RC file. */
165: wc.lpszClassName = "PlatformWClass"; /* Name used in call to CreateWindow. */
166:
167: /* Register the window class and return success/failure code. */
168:
169: return (RegisterClass(&wc));
170:
171: }
172:
173:
174: /****************************************************************************
175:
176: FUNCTION: InitInstance(HANDLE, int)
177:
178: PURPOSE: Saves instance handle and creates main window
179:
180: COMMENTS:
181:
182: This function is called at initialization time for every instance of
183: this application. This function performs initialization tasks that
184: cannot be shared by multiple instances.
185:
186: In this case, we save the instance handle in a static variable and
187: create and display the main program window.
188:
189: ****************************************************************************/
190:
191: BOOL InitInstance(HANDLE hInstance, /* Current instance identifier. */
192: int nCmdShow ) /* Param for first ShowWindow() call. */
193: {
194: HWND hWnd; /* Main window handle. */
195:
196: /* Save the instance handle in static variable, which will be used in */
197: /* many subsequence calls from this application to Windows. */
198:
199: hInst = hInstance;
200:
201: /* Create a main window for this application instance. */
202:
203: hWnd = CreateWindow(
204: "PlatformWClass", /* See RegisterClass() call. */
205: "Platform Sample Application", /* Text for window title bar. */
206: WS_OVERLAPPEDWINDOW, /* Window style. */
207: 10, /* Default horizontal position. */
208: 10, /* Default vertical position. */
209: 600, /* Default width. */
210: 400, /* Default height. */
211: NULL, /* Overlapped windows have no parent. */
212: NULL, /* Use the window class menu. */
213: hInstance, /* This instance owns this window. */
214: NULL /* Pointer not needed. */
215: );
216:
217: /* If window could not be created, return "failure" */
218:
219: if (!hWnd)
220: return (FALSE);
221:
222: /* Make the window visible; update its client area; and return "success" */
223:
224: ShowWindow(hWnd, nCmdShow); /* Show the window */
225: UpdateWindow(hWnd); /* Sends WM_PAINT message */
226: return (TRUE); /* Returns the value from PostQuitMessage */
227:
228: }
229:
230: /****************************************************************************
231:
232: FUNCTION: MainWndProc(HWND, WORD, WPARAM, LPARAM)
233:
234: PURPOSE: Processes messages
235:
236: MESSAGES:
237:
238: WM_COMMAND - application menu (About dialog box)
239: WM_DESTROY - destroy window
240:
241: COMMENTS:
242:
243: To process the IDM_ABOUT message, call MakeProcInstance() to get the
244: current instance address of the About() function. Then call Dialog
245: box which will create the box according to the information in your
246: Platform.rc file and turn control over to the About() function. When
247: it returns, free the intance address.
248:
249: ****************************************************************************/
250:
251: long FAR PASCAL MainWndProc(HWND hWnd, /* window handle */
252: UINT message, /* type of message */
253: WPARAM wParam, /* additional information */
254: LPARAM lParam ) /* additional information */
255: {
256: DLGPROC lpProcAbout;
257: DWORD version, flags;
258: char buf[80];
259:
260: switch (message) {
261:
262: case WM_COMMAND: /* message: command from application menu */
263: if (LOWORD(wParam) == IDM_ABOUT) {
264: lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, hInst );
265:
266: DialogBox(hInst, /* current instance */
267: "AboutBox", /* resource to use */
268: hWnd, /* parent handle */
269: lpProcAbout); /* About() instance address */
270:
271: FreeProcInstance((FARPROC)lpProcAbout);
272: break;
273: }
274: else if ( LOWORD(wParam) == IDM_PLATFORM ) {
275: version = GetVersion();
276: wsprintf( buf, "The version of Windows you're running is %d.%d",
277: LOBYTE(LOWORD(version)), HIBYTE(LOWORD(version)) );
278:
279: MessageBox( hWnd, buf, "Platform", MB_OK );
280: #if defined(_WIN32) || defined(WIN32)
281: /*
282: * bugbug Currently HIWORD of version is 500. The highbit is not set
283: */
284:
285: if ( version & WIN32S ) /* High bit set */
286: wsprintf ( buf, "This is running on Win32s" );
287: else
288: wsprintf ( buf, "This is running on Win32/NT" );
289:
290: // wsprintf( buf, "Verion = %#x", HIWORD(version) );
291: // MessageBox( hWnd, buf, "Platform", MB_OK );
292:
293:
294: UNREFERENCED_PARAMETER(flags);
295: #else
296: flags = GetWinFlags();
297: wsprintf ( buf, "flags are %#lx", flags );
298: MessageBox ( hWnd, buf, NULL, MB_OK );
299:
300: if ( flags & WF1_WINNT )
301: wsprintf ( buf, "This is running in the WOW layer" );
302: else
303: wsprintf( buf, "The version of MS-DOS you're running is %d.%d",
304: HIBYTE(HIWORD(version)), LOBYTE(HIWORD(version)) );
305: #endif
306: MessageBox( hWnd, buf, "Platform", MB_OK );
307: }
308: else /* Lets Windows process it */
309: return (DefWindowProc(hWnd, message, wParam, lParam));
310:
311: break;
312:
313: case WM_DESTROY: /* message: window being destroyed */
314: PostQuitMessage(0);
315: break;
316:
317: default: /* Passes it on if unproccessed */
318: return (DefWindowProc(hWnd, message, wParam, lParam));
319: }
320: return ( 0 );
321: }
322:
323:
324: /****************************************************************************
325:
326: FUNCTION: About(HWND, unsigned, WORD, LONG)
327:
328: PURPOSE: Processes messages for "About" dialog box
329:
330: MESSAGES:
331:
332: WM_INITDIALOG - initialize dialog box
333: WM_COMMAND - Input received
334:
335: COMMENTS:
336:
337: No initialization is needed for this particular dialog box, but TRUE
338: must be returned to Windows.
339:
340: Wait for user to click on "Ok" button, then close the dialog box.
341:
342: ****************************************************************************/
343:
344: BOOL FAR PASCAL About(HWND hDlg, /* window handle of the dialog box */
345: UINT message, /* type of message */
346: WPARAM wParam, /* message-specific information */
347: LPARAM lParam )
348: {
349: switch (message) {
350: case WM_INITDIALOG: /* message: initialize dialog box */
351: return (TRUE);
352:
353: case WM_COMMAND: /* message: received a command */
354: if (wParam == IDOK /* "OK" box selected? */
355: || wParam == IDCANCEL) { /* System menu close command? */
356: EndDialog(hDlg, TRUE); /* Exits the dialog box */
357: return (TRUE);
358: }
359: break;
360: }
361: return (FALSE); /* Didn't process a message */
362: UNREFERENCED_PARAMETER(lParam);
363: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.