|
|
1.1 root 1: /*---------------------------------------------------------------------------*\
2: | GDIDEMO MODULE
3: | This is the main entry-point module for the GDIDEMO application. It is
4: | intended to provide simple demonstrations of graphical functionality of
5: | WIN32. This module is only concerned with the FRAME-WINDOW object.
6: |
7: |
8: | segment: _TEXT (DOS16)
9: | created: 31-Oct-90
10: | history: 31-Oct-90 <chriswil> created.
11: |
12: \*---------------------------------------------------------------------------*/
13:
14: #include <windows.h>
15: #include "gdidemo.h"
16: #include "poly.h"
17: #include "xform.h"
18: #include "maze.h"
19: #include "draw.h"
20: #include "bounce.h"
21:
22: /*---------------------------------------------------------------------------*\
23: | WINDOWS MAIN PROCEDURE
24: | This is the process entry-point routine. This is the basis for all
25: | application events.
26: |
27: | created: 31-Oct-90
28: | history: 31-Oct-90 <chriswil> created.
29: |
30: \*---------------------------------------------------------------------------*/
31: int PASCAL WinMain(HANDLE hInst, HANDLE hPrevInst, LPSTR lpszLine, int nShow)
32: {
33: HWND hWndFrame;
34: MSG msg;
35:
36: lpszLine = lpszLine;
37:
38: /*
39: ** If there's a previous instance of this application, then we do not need
40: ** to register it again.
41: */
42: if(!hPrevInst)
43: if(!RegisterAppClass(hInst))
44: return(1);
45:
46:
47: /*
48: ** Enter the application message-polling loop. This is the anchor for
49: ** the application.
50: */
51: msg.wParam = 1;
52: if(hWndFrame = CreateAppWindow(hInst))
53: {
54: ShowWindow(hWndFrame,nShow);
55: UpdateWindow(hWndFrame);
56:
57: while(GetMessage(&msg,NULL,0,0))
58: {
59: TranslateMessage(&msg);
60: DispatchMessage(&msg);
61: }
62: }
63: UnregisterAppClass(hInst);
64:
65: return(msg.wParam);
66: }
67:
68:
69: /*---------------------------------------------------------------------------*\
70: | CLIENT WINDOW PROCEDURE
71: | This is the main window function for the client-window created. This is
72: | the frame window which encompasses the MDI control window.
73: |
74: | created: 31-Oct-90
75: | history: 31-Oct-90 <chriswil> created.
76: |
77: \*---------------------------------------------------------------------------*/
78: LONG APIENTRY WndProc(HWND hWndFrame, UINT wMsg, WPARAM wParam, LONG lParam)
79: {
80: HWND hWndClient;
81:
82:
83: switch(wMsg)
84: {
85: /*
86: ** Set up any pre-display stuff. This is where we create the MDI
87: ** control window.
88: */
89: case WM_CREATE:
90: CreateProc(hWndFrame);
91: break;
92:
93:
94: /*
95: ** Paint the background of the frame. This really is a NOP since
96: ** the MDI control is displayed over the frame's client window.
97: */
98: case WM_PAINT:
99: PaintProc(hWndFrame);
100: break;
101:
102:
103: /*
104: ** Time to die.
105: */
106: case WM_DESTROY:
107: DestroyProc(hWndFrame);
108: break;
109:
110:
111: /*
112: ** Process the frame-commands. We need to let the default handler
113: ** have this event, since the MDI control handles the
114: ** commands as well.
115: */
116: case WM_COMMAND:
117: CommandProc(hWndFrame,wParam,lParam);
118:
119:
120: /*
121: ** Since this is the frame-window, we need to grab the MDI client
122: ** control window to pass to the MDI control. We store this as
123: ** part of the extra-object information for the frame-window.
124: */
125: default:
126: hWndClient = (HWND)GetWindowLong(hWndFrame,CLIENTWND);
127: return(DefFrameProc(hWndFrame,hWndClient,wMsg,wParam,lParam));
128: }
129: return(0l);
130: }
131:
132:
133: /*---------------------------------------------------------------------------*\
134: | CLIENT CREATE PROCEDURE
135: | This is the main event-handler for the WM_CREATE message. It is here
136: | we create the MDI control window for the application. We store this
137: | information as part of the frame-window extra object information.
138: |
139: | created: 31-Oct-90
140: | history: 31-Oct-90 <chriswil> created.
141: |
142: \*---------------------------------------------------------------------------*/
143: BOOL CreateProc(HWND hWndFrame)
144: {
145: HMENU hMenu;
146: HWND hWnd;
147:
148:
149: /*
150: ** Set the window information to contain the child window.
151: */
152: if(hWnd = CreateMDIClientWindow(hWndFrame))
153: SetWindowLong(hWndFrame,CLIENTWND,(LONG)hWnd);
154:
155: if(hMenu = GetSubMenu(GetMenu(hWndFrame),0))
156: {
157: ModifyMenu(hMenu,IDM_DEMO_XFORM ,MF_BYCOMMAND | MF_GRAYED,IDM_DEMO_XFORM ,"&XForm");
158: ModifyMenu(hMenu,IDM_DEMO_MAZE ,MF_BYCOMMAND | MF_GRAYED,IDM_DEMO_MAZE ,"&Maze");
159: DrawMenuBar(hWndFrame);
160: }
161:
162: return(TRUE);
163: }
164:
165:
166: /*---------------------------------------------------------------------------*\
167: | COMMAND PROCEDURE
168: | This is the main event-handler for the WM_COMMAND event for the window
169: | application. All we really do is process the MENU commands for creating
170: | the DEMO windows.
171: |
172: | created: 31-Oct-90
173: | history: 31-Oct-90 <chriswil> created.
174: |
175: \*---------------------------------------------------------------------------*/
176: BOOL CommandProc(HWND hWndFrame, WPARAM wParam, LONG lParam)
177: {
178: HWND hWndClient;
179:
180: lParam = lParam;
181:
182: switch(wParam)
183: {
184: /*
185: ** Demo the poly-bezier window.
186: */
187: case IDM_DEMO_POLYBEZIER:
188: if(hWndClient = (HWND)GetWindowLong(hWndFrame,CLIENTWND))
189: CreatePolyWindow(hWndClient,0);
190: break;
191:
192:
193: /*
194: ** Demo the xform's.
195: */
196: case IDM_DEMO_XFORM:
197: if(hWndClient = (HWND)GetWindowLong(hWndFrame,CLIENTWND))
198: CreateXFormWindow(hWndClient,0);
199: break;
200:
201:
202: /*
203: ** Demo the maze.
204: */
205: case IDM_DEMO_MAZE:
206: if(hWndClient = (HWND)GetWindowLong(hWndFrame,CLIENTWND))
207: CreateMazeWindow(hWndClient,0);
208: break;
209:
210:
211: /*
212: ** Demo random drawing objects.
213: */
214: case IDM_DEMO_DRAW:
215: if(hWndClient = (HWND)GetWindowLong(hWndFrame,CLIENTWND))
216: CreateDrawWindow(hWndClient,0);
217: break;
218:
219:
220: /*
221: ** Demo bouncing region balls.
222: */
223: case IDM_DEMO_BOUNCE:
224: if(hWndClient = (HWND)GetWindowLong(hWndFrame,CLIENTWND))
225: CreateBounceWindow(hWndClient,0);
226: break;
227:
228:
229: /*
230: ** MDI cascade the demo windows.
231: */
232: case IDM_WINDOW_CASCADE:
233: if(hWndClient = (HWND)GetWindowLong(hWndFrame,CLIENTWND))
234: SendMessage(hWndClient,WM_MDICASCADE,0,0l);
235: break;
236:
237:
238: /*
239: ** MDI tile the demo windows.
240: */
241: case IDM_WINDOW_TILE:
242: if(hWndClient = (HWND)GetWindowLong(hWndFrame,CLIENTWND))
243: SendMessage(hWndClient,WM_MDITILE,0,0l);
244: break;
245:
246:
247: /*
248: ** MDI arrange the MDI icons.
249: */
250: case IDM_WINDOW_ICON:
251: if(hWndClient = (HWND)GetWindowLong(hWndFrame,CLIENTWND))
252: SendMessage(hWndClient,WM_MDIICONARRANGE,0,0l);
253: break;
254:
255:
256: /*
257: ** Display the about box.
258: */
259: case IDM_HELP_ABOUT:
260: DisplayDialogBox(hWndFrame,MAKEINTRESOURCE(ABOUTBOX),(WNDPROC)AboutDlgProc,0l);
261: break;
262:
263:
264: /*
265: ** Command not recognized.
266: */
267: default:
268: return(FALSE);
269: }
270: return(TRUE);
271: }
272:
273:
274: /*---------------------------------------------------------------------------*\
275: | CLIENT PAINT PROCEDURE
276: | This is the main event-handler for the WM_PAINT message.
277: |
278: | created: 31-Oct-90
279: | history: 31-Oct-90 <chriswil> created.
280: |
281: \*---------------------------------------------------------------------------*/
282: VOID PaintProc(HWND hWndFrame)
283: {
284: HDC hDC;
285: PAINTSTRUCT ps;
286:
287:
288: if(hDC = BeginPaint(hWndFrame,&ps))
289: EndPaint(hWndFrame,&ps);
290:
291: return;
292: }
293:
294:
295: /*---------------------------------------------------------------------------*\
296: | CLIENT DESTROY PROCEDURE
297: | This routine is called to cleanup global resources upon exit of the
298: | application.
299: |
300: | created: 31-Oct-90
301: | history: 31-Oct-90 <chriswil> created.
302: |
303: \*---------------------------------------------------------------------------*/
304: VOID DestroyProc(HWND hWndFrame)
305: {
306: hWndFrame = hWndFrame;
307:
308: PostQuitMessage(0);
309:
310: return;
311: }
312:
313:
314:
315: DWORD FAR lRandom(VOID)
316: {
317: static DWORD glSeed = (DWORD)-365387184;
318:
319: glSeed *= 69069;
320: return(++glSeed);
321: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.