Advertisement
Guest User

winMain.cpp

a guest
Dec 1st, 2011
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.08 KB | None | 0 0
  1. #include <windows.h>
  2. #include <tchar.h>
  3. #include <stdio.h>
  4.  
  5. #include <vector>
  6. using namespace std;
  7.  
  8. #include "dxSystem.h"
  9.  
  10. /*******************************************************************
  11. * Global Variables
  12. *******************************************************************/
  13. HWND hWnd;                  //window handle
  14. int windowWidth = 800; 
  15. int windowHeight = 600;
  16.  
  17. //directX manager
  18. dxSystem* dx;
  19.  
  20. /*******************************************************************
  21. * Main Window Procedure - handles application events
  22. *******************************************************************/
  23. LRESULT CALLBACK wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  24. {
  25.     switch (message)
  26.     {
  27.         // Allow the user to press the escape key to end the application
  28.     case WM_KEYDOWN :   switch(wParam)
  29.                         {                              
  30.     case VK_ESCAPE : PostQuitMessage(0);
  31.         break;
  32.                         }
  33.  
  34.                         break;     
  35.  
  36.                         // The user hit the close button, close the application
  37.     case WM_DESTROY :   PostQuitMessage(0);
  38.         break;
  39.     }
  40.  
  41.     return DefWindowProc(hWnd, message, wParam, lParam);
  42. }
  43.  
  44. /*******************************************************************
  45. * Initialize Main Window
  46. ********************************************************************/
  47. bool initWindow(HWND &hWnd, HINSTANCE hInstance, int width, int height)
  48. {
  49.     WNDCLASSEX wcex;
  50.  
  51.     wcex.cbSize         = sizeof(WNDCLASSEX);
  52.     wcex.style          = CS_HREDRAW | CS_VREDRAW;
  53.     wcex.lpfnWndProc    = (WNDPROC)wndProc;
  54.     wcex.cbClsExtra     = 0;
  55.     wcex.cbWndExtra     = 0;
  56.     wcex.hInstance      = hInstance;
  57.     wcex.hIcon          = 0;
  58.     wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
  59.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  60.     wcex.lpszMenuName   = NULL;
  61.     wcex.lpszClassName  = TEXT("DXTutorial");
  62.     wcex.hIconSm        = 0;
  63.     RegisterClassEx(&wcex);
  64.  
  65.     //Resize the window
  66.     RECT rect = { 0, 0, width, height };
  67.     AdjustWindowRect(&rect, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, FALSE);
  68.  
  69.     //create the window from the class defined above   
  70.     hWnd = CreateWindow( L"ENGINE",
  71.           L"ENGINE",
  72.         WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
  73.         CW_USEDEFAULT,
  74.         CW_USEDEFAULT,
  75.         rect.right - rect.left,
  76.         rect.bottom - rect.top,
  77.         NULL,
  78.         NULL,
  79.         hInstance,
  80.         NULL);
  81.  
  82.     //window handle not created
  83.     if (!hWnd) return false;
  84.  
  85.     //if window creation was successful
  86.     ShowWindow(hWnd, SW_SHOW);
  87.     UpdateWindow(hWnd);
  88.     return true;
  89. }
  90.  
  91. /*******************************************************************
  92. * WinMain
  93. *******************************************************************/
  94. int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow )
  95. {
  96.     // Set up the application window
  97.     initWindow(hWnd, hInstance, windowWidth, windowHeight);
  98.  
  99.     //set up directx manager
  100.     dx->initialise(windowWidth, windowHeight, &hWnd);
  101.  
  102.     // Main message loop
  103.     MSG msg = {0};
  104.     while (WM_QUIT != msg.message)
  105.     {
  106.         while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE)
  107.         {
  108.             TranslateMessage(&msg);
  109.             DispatchMessage(&msg);         
  110.         }  
  111.  
  112.         dx->render();
  113.     }
  114.  
  115.     dx->shutDown();
  116.     delete dx;
  117.     dx = 0;
  118.  
  119.     return (int) msg.wParam;
  120. }
  121.  
  122.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement