home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / graphics / gdi / gdidemo / gdidemo.c < prev    next >
C/C++ Source or Header  |  1997-10-05  |  9KB  |  304 lines

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