Ember

wndproc

Feb 20th, 2014
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 KB | None | 0 0
  1. // Default message handler ------------------------------------------------------------
  2. LRESULT CALLBACK WndProc(HWND hwnd, UINT umessage, WPARAM wparam, LPARAM lparam)
  3. {
  4.     switch(umessage)
  5.     {
  6.         // Check if the window is being destroyed
  7.         case WM_DESTROY:
  8.         {
  9.             PostQuitMessage(0);
  10.             return 0;
  11.         }
  12.  
  13.         // Check if the window is being closed
  14.         case WM_CLOSE:
  15.         {
  16.             PostQuitMessage(0);
  17.             return 0;
  18.         }
  19.  
  20.         // All other messages pass to the message handler in the engine
  21.         default:
  22.         {
  23.             return Engine::Get()->MessageHandler(hwnd, umessage, wparam, lparam);
  24.         }
  25.     }
  26. }
  27.  
  28. // Application message handler --------------------------------------------------------
  29. LRESULT CALLBACK Engine::MessageHandler(HWND hwnd, UINT umessage, WPARAM wparam, LPARAM lparam)
  30. {
  31.     switch(umessage)
  32.     {
  33.         case WM_SIZE:
  34.         {
  35.             Float screenWidth, screenHeight;
  36.             bool result;
  37.  
  38.             // Get the new window dimensions
  39.             screenWidth = LOWORD(lparam);
  40.             screenHeight = HIWORD(lparam);
  41.  
  42.             // Resize the window and buffers
  43.             result = mWindow.Resize(screenWidth, screenHeight);
  44.             if(!result) { MessageBoxW(hwnd, L"Error resizing the swap chain buffers.", L"An error has occured", MB_OK); PostQuitMessage(0); }
  45.  
  46.             return 0;
  47.         }
  48.  
  49.         // Check if a key has been pressed on the keyboard
  50.         case WM_KEYDOWN:
  51.         {
  52.             // If a key is pressed send it to the input object so it can record that state
  53.             //mInput->KeyDown((UInt)wparam);
  54.             return 0;
  55.         }
  56.  
  57.         // Check if a key has been released on the keyboard
  58.         case WM_KEYUP:
  59.         {
  60.             // If a key is released then send it to the input object so it can unset the state for that key
  61.             //mInput->KeyUp((UInt)wparam);
  62.             return 0;
  63.         }
  64.  
  65.         // All other messages pass to the default message handler
  66.         default:
  67.         {
  68.             return DefWindowProc(hwnd, umessage, wparam, lparam);
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment