LRESULT GEN::GameEngine::HandleEvent(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam) { // Route Windows messages to game engine member functions switch (msg) { case WM_SETFOCUS: // Activate the game and update the Sleep status GameActivate(hWindow); SetSleep(FALSE); return 0; case WM_KILLFOCUS: // Deactivate the game and update the Sleep status GameDeactivate(hWindow); SetSleep(TRUE); return 0; case WM_PAINT: HDC hDC; PAINTSTRUCT ps; hDC = BeginPaint(hWindow, &ps); // Paint the game GamePaint(hDC); EndPaint(hWindow, &ps); return 0; case MM_MCINOTIFY: if (LOWORD(wParam) == MCI_NOTIFY_SUCCESSFUL) { if (GetMIDIPlayer() != nullptr) GetMIDIPlayer()->Restart(hWindow); } return 0; // Mouse Input Cases case WM_LBUTTONDOWN: // handle mouse button MouseButtonDown(LOWORD(lParam), HIWORD(lParam), TRUE); return 0; case WM_LBUTTONUP: MouseButtonUp(LOWORD(lParam), HIWORD(lParam), TRUE); return 0; case WM_RBUTTONDOWN: MouseButtonDown(LOWORD(lParam), HIWORD(lParam), FALSE); return 0; case WM_RBUTTONUP: MouseButtonUp(LOWORD(lParam), HIWORD(lParam), FALSE); return 0; case WM_MOUSEMOVE: MouseMove(LOWORD(lParam), HIWORD(lParam)); return 0; } return DefWindowProc(hWindow, msg, wParam, lParam); }
LRESULT GameEngine::HandleEvent(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam) { //Route Windows messages to game engine member fucntions switch (msg) { case WM_CREATE: //Set the game window and start the game SetWindow(hWindow); GameStart(hWindow); return 0; case WM_ACTIVATE: //Activate and deactivate the game and update the Sleep status if (wParam != WA_INACTIVE) { GameActivate(hWindow); SetSleep(FALSE); } else { GameDeactivate(hWindow); SetSleep(TRUE); } return 0; case WM_PAINT: HDC hDC; PAINTSTRUCT ps; hDC = BeginPaint(hWindow, &ps); //Paint the game GamePaint(hDC); EndPaint(hWindow, &ps); return 0; case WM_LBUTTONDOWN: //Handle left mouse button press MouseButtonDown(LOWORD(lParam), HIWORD(lParam), TRUE); return 0; case WM_LBUTTONUP: //Handle left mouse button release MouseButtonUp(LOWORD(lParam), HIWORD(lParam), TRUE); return 0; case WM_RBUTTONDOWN: //Handle right mouse button press MouseButtonDown(LOWORD(lParam), HIWORD(lParam), FALSE); return 0; case WM_RBUTTONUP: //Handle right mouse button release MouseButtonUp(LOWORD(lParam), HIWORD(lParam), FALSE); return 0; case WM_MOUSEMOVE: //Handle mouse movement MouseMove(LOWORD(lParam), HIWORD(lParam)); return 0; case WM_DESTROY: //End the game and exit the application GameEnd(); PostQuitMessage(0); return 0; } return DefWindowProc(hWindow, msg, wParam, lParam); }