Message Handling


SUBMITTED BY: Guest

DATE: Dec. 27, 2013, 5:01 a.m.

FORMAT: C++

SIZE: 2.1 kB

HITS: 788

  1. // Global variables -------------------------------------------------------------------
  2. static Engine* ApplicationHandle = 0;
  3. // Default message handler ------------------------------------------------------------
  4. static LRESULT CALLBACK WndProc(HWND hwnd, UINT umessage, WPARAM wparam, LPARAM lparam)
  5. {
  6. switch(umessage)
  7. {
  8. // Check if the window is being destroyed
  9. case WM_DESTROY:
  10. {
  11. PostQuitMessage(0);
  12. return 0;
  13. }
  14. // Check if the window is being closed
  15. case WM_CLOSE:
  16. {
  17. PostQuitMessage(0);
  18. return 0;
  19. }
  20. // All other messages pass to the message handler in the system class
  21. default:
  22. {
  23. return ApplicationHandle->MessageHandler(hwnd, umessage, wparam, lparam);
  24. }
  25. }
  26. }
  27. // Application message handler --------------------------------------------------------
  28. LRESULT CALLBACK MessageHandler(HWND hwnd, UINT umessage, WPARAM wparam, LPARAM lparam)
  29. {
  30. switch(umessage)
  31. {
  32. // Check if a key has been pressed on the keyboard
  33. case WM_KEYDOWN:
  34. {
  35. // If a key is pressed send it to the input object so it can record that state
  36. mInput->KeyDown((unsigned int)wparam);
  37. return 0;
  38. }
  39. // Check if a key has been released on the keyboard
  40. case WM_KEYUP:
  41. {
  42. // If a key is released then send it to the input object so it can unset the state for that key
  43. mInput->KeyUp((unsigned int)wparam);
  44. return 0;
  45. }
  46. // All other messages pass to the default message handler
  47. default:
  48. {
  49. return DefWindowProc(hwnd, umessage, wparam, lparam);
  50. }
  51. }
  52. }

comments powered by Disqus