home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / common / msdev98 / bin / ide / exewz.awx / TEMPLATE / ROOT.CPP < prev    next >
C/C++ Source or Header  |  1998-06-18  |  5KB  |  201 lines

  1. // $$root$$.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. $$IF(HELLO)
  6. #include "resource.h"
  7.  
  8. #define MAX_LOADSTRING 100
  9.  
  10. // Global Variables:
  11. HINSTANCE hInst;                                // current instance
  12. TCHAR szTitle[MAX_LOADSTRING];                                // The title bar text
  13. TCHAR szWindowClass[MAX_LOADSTRING];                                // The title bar text
  14.  
  15. // Foward declarations of functions included in this code module:
  16. ATOM                MyRegisterClass(HINSTANCE hInstance);
  17. BOOL                InitInstance(HINSTANCE, int);
  18. LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
  19. LRESULT CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
  20. $$ENDIF
  21.  
  22. int APIENTRY WinMain(HINSTANCE hInstance,
  23.                      HINSTANCE hPrevInstance,
  24.                      LPSTR     lpCmdLine,
  25.                      int       nCmdShow)
  26. {
  27.      // TODO: Place code here.
  28. $$IF(HELLO)
  29.     MSG msg;
  30.     HACCEL hAccelTable;
  31.  
  32.     // Initialize global strings
  33.     LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  34.     LoadString(hInstance, IDC_$$SAFE_ROOT$$, szWindowClass, MAX_LOADSTRING);
  35.     MyRegisterClass(hInstance);
  36.  
  37.     // Perform application initialization:
  38.     if (!InitInstance (hInstance, nCmdShow)) 
  39.     {
  40.         return FALSE;
  41.     }
  42.  
  43.     hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_$$SAFE_ROOT$$);
  44.  
  45.     // Main message loop:
  46.     while (GetMessage(&msg, NULL, 0, 0)) 
  47.     {
  48.         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
  49.         {
  50.             TranslateMessage(&msg);
  51.             DispatchMessage(&msg);
  52.         }
  53.     }
  54.  
  55.     return msg.wParam;
  56. $$ELSE
  57.  
  58.     return 0;
  59. $$ENDIF
  60. }
  61.  
  62.  
  63.  
  64. $$IF(HELLO)
  65. //
  66. //  FUNCTION: MyRegisterClass()
  67. //
  68. //  PURPOSE: Registers the window class.
  69. //
  70. //  COMMENTS:
  71. //
  72. //    This function and its usage is only necessary if you want this code
  73. //    to be compatible with Win32 systems prior to the 'RegisterClassEx'
  74. //    function that was added to Windows 95. It is important to call this function
  75. //    so that the application will get 'well formed' small icons associated
  76. //    with it.
  77. //
  78. ATOM MyRegisterClass(HINSTANCE hInstance)
  79. {
  80.     WNDCLASSEX wcex;
  81.  
  82.     wcex.cbSize = sizeof(WNDCLASSEX); 
  83.  
  84.     wcex.style            = CS_HREDRAW | CS_VREDRAW;
  85.     wcex.lpfnWndProc    = (WNDPROC)WndProc;
  86.     wcex.cbClsExtra        = 0;
  87.     wcex.cbWndExtra        = 0;
  88.     wcex.hInstance        = hInstance;
  89.     wcex.hIcon            = LoadIcon(hInstance, (LPCTSTR)IDI_$$SAFE_ROOT$$);
  90.     wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
  91.     wcex.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
  92.     wcex.lpszMenuName    = (LPCSTR)IDC_$$SAFE_ROOT$$;
  93.     wcex.lpszClassName    = szWindowClass;
  94.     wcex.hIconSm        = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
  95.  
  96.     return RegisterClassEx(&wcex);
  97. }
  98.  
  99. //
  100. //   FUNCTION: InitInstance(HANDLE, int)
  101. //
  102. //   PURPOSE: Saves instance handle and creates main window
  103. //
  104. //   COMMENTS:
  105. //
  106. //        In this function, we save the instance handle in a global variable and
  107. //        create and display the main program window.
  108. //
  109. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  110. {
  111.    HWND hWnd;
  112.  
  113.    hInst = hInstance; // Store instance handle in our global variable
  114.  
  115.    hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  116.       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  117.  
  118.    if (!hWnd)
  119.    {
  120.       return FALSE;
  121.    }
  122.  
  123.    ShowWindow(hWnd, nCmdShow);
  124.    UpdateWindow(hWnd);
  125.  
  126.    return TRUE;
  127. }
  128.  
  129. //
  130. //  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
  131. //
  132. //  PURPOSE:  Processes messages for the main window.
  133. //
  134. //  WM_COMMAND    - process the application menu
  135. //  WM_PAINT    - Paint the main window
  136. //  WM_DESTROY    - post a quit message and return
  137. //
  138. //
  139. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  140. {
  141.     int wmId, wmEvent;
  142.     PAINTSTRUCT ps;
  143.     HDC hdc;
  144.     TCHAR szHello[MAX_LOADSTRING];
  145.     LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
  146.  
  147.     switch (message) 
  148.     {
  149.         case WM_COMMAND:
  150.             wmId    = LOWORD(wParam); 
  151.             wmEvent = HIWORD(wParam); 
  152.             // Parse the menu selections:
  153.             switch (wmId)
  154.             {
  155.                 case IDM_ABOUT:
  156.                    DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
  157.                    break;
  158.                 case IDM_EXIT:
  159.                    DestroyWindow(hWnd);
  160.                    break;
  161.                 default:
  162.                    return DefWindowProc(hWnd, message, wParam, lParam);
  163.             }
  164.             break;
  165.         case WM_PAINT:
  166.             hdc = BeginPaint(hWnd, &ps);
  167.             // TODO: Add any drawing code here...
  168.             RECT rt;
  169.             GetClientRect(hWnd, &rt);
  170.             DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
  171.             EndPaint(hWnd, &ps);
  172.             break;
  173.         case WM_DESTROY:
  174.             PostQuitMessage(0);
  175.             break;
  176.         default:
  177.             return DefWindowProc(hWnd, message, wParam, lParam);
  178.    }
  179.    return 0;
  180. }
  181.  
  182. // Mesage handler for about box.
  183. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  184. {
  185.     switch (message)
  186.     {
  187.         case WM_INITDIALOG:
  188.                 return TRUE;
  189.  
  190.         case WM_COMMAND:
  191.             if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
  192.             {
  193.                 EndDialog(hDlg, LOWORD(wParam));
  194.                 return TRUE;
  195.             }
  196.             break;
  197.     }
  198.     return FALSE;
  199. }
  200. $$ENDIF
  201.