INIT.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:7k
源码类别:

Windows编程

开发平台:

Visual C++

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