Ember

Message Handling

Dec 26th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1.     // Global variables -------------------------------------------------------------------
  2.     static Engine* ApplicationHandle = 0;
  3.  
  4.     // Default message handler ------------------------------------------------------------
  5.     static LRESULT CALLBACK WndProc(HWND hwnd, UINT umessage, WPARAM wparam, LPARAM lparam)
  6.     {
  7.         switch(umessage)
  8.         {
  9.             // Check if the window is being destroyed
  10.             case WM_DESTROY:
  11.             {
  12.                 PostQuitMessage(0);
  13.                 return 0;
  14.             }
  15.  
  16.             // Check if the window is being closed
  17.             case WM_CLOSE:
  18.             {
  19.                 PostQuitMessage(0);
  20.                 return 0;
  21.             }
  22.  
  23.             // All other messages pass to the message handler in the system class
  24.             default:
  25.             {
  26.                 return ApplicationHandle->MessageHandler(hwnd, umessage, wparam, lparam);
  27.             }
  28.         }
  29.     }
  30.  
  31.     // Application message handler --------------------------------------------------------
  32.     LRESULT CALLBACK MessageHandler(HWND hwnd, UINT umessage, WPARAM wparam, LPARAM lparam)
  33.     {
  34.         switch(umessage)
  35.         {
  36.             // Check if a key has been pressed on the keyboard
  37.             case WM_KEYDOWN:
  38.             {
  39.                 // If a key is pressed send it to the input object so it can record that state
  40.                 mInput->KeyDown((unsigned int)wparam);
  41.                 return 0;
  42.             }
  43.  
  44.             // Check if a key has been released on the keyboard
  45.             case WM_KEYUP:
  46.             {
  47.                 // If a key is released then send it to the input object so it can unset the state for that key
  48.                 mInput->KeyUp((unsigned int)wparam);
  49.                 return 0;
  50.             }
  51.  
  52.             // All other messages pass to the default message handler
  53.             default:
  54.             {
  55.                 return DefWindowProc(hwnd, umessage, wparam, lparam);
  56.             }
  57.         }
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment