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 / init.c < prev    next >
C/C++ Source or Header  |  1997-10-05  |  7KB  |  220 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. | INITIALIZATION MODULE
  14. |   This module contains startup-routines for the creation of windows for this
  15. |   application.
  16. |
  17. |   RegisterAppClass
  18. |   UnregisterAppClass
  19. |   CreateAppWindow
  20. |   CreateMDIClientWindow
  21. |
  22. \*---------------------------------------------------------------------------*/
  23.  
  24. #include <windows.h>
  25. #include "gdidemo.h"
  26. #include "poly.h"
  27. #include "xform.h"
  28. #include "maze.h"
  29. #include "draw.h"
  30. #include "bounce.h"
  31.  
  32. /*---------------------------------------------------------------------------*\
  33. | REGISTER APPLICATION CLASS
  34. |   This routine registers all classes necessary for the application.
  35. \*---------------------------------------------------------------------------*/
  36. BOOL FAR RegisterAppClass(HANDLE hInstance)
  37. {
  38.     WNDCLASS wndClass;
  39.  
  40.  
  41.     /*
  42.     ** Set the common wndClass information.  This is common to all windows
  43.     ** of this application.
  44.     */
  45.     wndClass.style         = CS_HREDRAW | CS_VREDRAW;
  46.     wndClass.cbClsExtra    = 0;
  47.     wndClass.cbWndExtra    = sizeof(LONG);
  48.     wndClass.hCursor       = LoadCursor(NULL,IDC_ARROW);
  49.     wndClass.hInstance     = hInstance;
  50.  
  51.  
  52.     /*
  53.     ** Register the main top-level window (frame).
  54.     */
  55.     wndClass.lpfnWndProc   = WndProc;
  56.     wndClass.hIcon         = LoadIcon(hInstance,MAKEINTRESOURCE(APPICON));
  57.     wndClass.hbrBackground = GetStockObject(WHITE_BRUSH);
  58.     wndClass.lpszMenuName  = MAKEINTRESOURCE(APPMENU);
  59.     wndClass.lpszClassName = APPCLASS;
  60.  
  61.     if(!RegisterClass(&wndClass))
  62.         return(FALSE);
  63.  
  64.  
  65.     /*
  66.     ** Register the polybezier demo window.
  67.     */
  68.     wndClass.lpfnWndProc   = PolyProc;
  69.     wndClass.hIcon         = LoadIcon(NULL,IDI_APPLICATION);
  70.     wndClass.hbrBackground = GetStockObject(BLACK_BRUSH);
  71.     wndClass.lpszMenuName  = NULL;
  72.     wndClass.lpszClassName = POLYCLASS;
  73.  
  74.     if(!RegisterClass(&wndClass))
  75.     {
  76.         UnregisterClass(APPCLASS,hInstance);
  77.         return(FALSE);
  78.     }
  79.  
  80.  
  81.     /*
  82.     ** Register the xform demo window.
  83.     */
  84.     wndClass.lpfnWndProc   = XFormProc;
  85.     wndClass.hIcon         = LoadIcon(NULL,IDI_APPLICATION);
  86.     wndClass.hbrBackground = GetStockObject(BLACK_BRUSH);
  87.     wndClass.lpszMenuName  = NULL;
  88.     wndClass.lpszClassName = XFORMCLASS;
  89.  
  90.     if(!RegisterClass(&wndClass))
  91.     {
  92.         UnregisterClass(APPCLASS ,hInstance);
  93.         UnregisterClass(POLYCLASS,hInstance);
  94.         return(FALSE);
  95.     }
  96.  
  97.  
  98.     /*
  99.     ** Register the maze demo window.
  100.     */
  101.     wndClass.lpfnWndProc   = MazeProc;
  102.     wndClass.hIcon         = LoadIcon(NULL,IDI_APPLICATION);
  103.     wndClass.hbrBackground = GetStockObject(BLACK_BRUSH);
  104.     wndClass.lpszMenuName  = NULL;
  105.     wndClass.lpszClassName = MAZECLASS;
  106.  
  107.     if(!RegisterClass(&wndClass))
  108.     {
  109.         UnregisterClass(APPCLASS  ,hInstance);
  110.         UnregisterClass(POLYCLASS ,hInstance);
  111.         UnregisterClass(XFORMCLASS,hInstance);
  112.         return(FALSE);
  113.     }
  114.  
  115.  
  116.     /*
  117.     ** Register the random draw demo window.
  118.     */
  119.     wndClass.lpfnWndProc   = DrawProc;
  120.     wndClass.hIcon         = LoadIcon(NULL,IDI_APPLICATION);
  121.     wndClass.hbrBackground = GetStockObject(WHITE_BRUSH);
  122.     wndClass.lpszMenuName  = NULL;
  123.     wndClass.lpszClassName = DRAWCLASS;
  124.  
  125.     if(!RegisterClass(&wndClass))
  126.     {
  127.         UnregisterClass(APPCLASS  ,hInstance);
  128.         UnregisterClass(POLYCLASS ,hInstance);
  129.         UnregisterClass(XFORMCLASS,hInstance);
  130.         UnregisterClass(MAZECLASS ,hInstance);
  131.         return(FALSE);
  132.     }
  133.  
  134.  
  135.     /*
  136.     ** Register the bouncing ball demo window.
  137.     */
  138.     wndClass.lpfnWndProc   = BounceProc;
  139.     wndClass.hIcon         = LoadIcon(NULL,IDI_APPLICATION);
  140.     wndClass.hbrBackground = GetStockObject(WHITE_BRUSH);
  141.     wndClass.lpszMenuName  = NULL;
  142.     wndClass.lpszClassName = BOUNCECLASS;
  143.  
  144.     if(!RegisterClass(&wndClass))
  145.     {
  146.         UnregisterClass(APPCLASS  ,hInstance);
  147.         UnregisterClass(POLYCLASS ,hInstance);
  148.         UnregisterClass(XFORMCLASS,hInstance);
  149.         UnregisterClass(MAZECLASS ,hInstance);
  150.         UnregisterClass(DRAWCLASS ,hInstance);
  151.         return(FALSE);
  152.     }
  153.  
  154.     return(TRUE);
  155. }
  156.  
  157.  
  158. /*---------------------------------------------------------------------------*\
  159. | UNREGISTER APPLICATION CLASS
  160. |   This routine unregisters all classes registered for the application.
  161. |   It is typically called upon termination of the application.
  162. \*---------------------------------------------------------------------------*/
  163. VOID FAR UnregisterAppClass(HANDLE hInstance)
  164. {
  165.     UnregisterClass(APPCLASS   ,hInstance);
  166.     UnregisterClass(POLYCLASS  ,hInstance);
  167.     UnregisterClass(XFORMCLASS ,hInstance);
  168.     UnregisterClass(MAZECLASS  ,hInstance);
  169.     UnregisterClass(DRAWCLASS  ,hInstance);
  170.     UnregisterClass(BOUNCECLASS,hInstance);
  171.  
  172.     return;
  173. }
  174.  
  175.  
  176. /*---------------------------------------------------------------------------*\
  177. | CREATE APPLICATION WINDOW
  178. |   This routine creates the main top-level window.
  179. \*---------------------------------------------------------------------------*/
  180. HWND FAR CreateAppWindow(HANDLE hInstance)
  181. {
  182.     /*
  183.     ** Upon creation of the window, initialize the extra object information.
  184.     */
  185.     return(CreateWindow(APPCLASS,APPTITLE,WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  186.             CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
  187.             NULL,NULL,hInstance,NULL));
  188. }
  189.  
  190.  
  191. /*---------------------------------------------------------------------------*\
  192. | CREATE MDI CLIENT WINDOW
  193. |   This routine creates the client window which handles the MDI windows.
  194. |   The window will eventually be size to fit into the frame-window's client
  195. |   area.
  196. \*---------------------------------------------------------------------------*/
  197. HWND FAR CreateMDIClientWindow(HWND hWndFrame)
  198. {
  199.     HWND               hWndClient;
  200.     HANDLE             hInstance;
  201.     CLIENTCREATESTRUCT ccs;
  202.  
  203.  
  204.     /*
  205.     ** Initialize the client struct to point to define the menu and child
  206.     ** identifiers.  The menu item specifies the parent menu in which the
  207.     ** the list of MDI childs will be appended to this menu.
  208.     */
  209.     ccs.hWindowMenu  = NULL;
  210.     ccs.idFirstChild = 0;
  211.  
  212.  
  213.     hInstance = GETINSTANCE(hWndFrame);
  214.  
  215.     hWndClient = CreateWindow("MDICLIENT",NULL,WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
  216.             0,0,1,1,hWndFrame,NULL,hInstance,(LPVOID)&ccs);
  217.  
  218.     return(hWndClient);
  219. }
  220.