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