LRESULT Window::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_ACTIVATE: active_ = (WA_INACTIVE != LOWORD(wParam)); this->OnActive()(*this, active_); break; case WM_ERASEBKGND: return 1; case WM_PAINT: this->OnPaint()(*this); break; case WM_ENTERSIZEMOVE: // Previent rendering while moving / sizing ready_ = false; this->OnEnterSizeMove()(*this); break; case WM_EXITSIZEMOVE: this->OnExitSizeMove()(*this); ready_ = true; break; case WM_SIZE: // Check to see if we are losing or gaining our window. Set the // active flag to match if ((SIZE_MAXHIDE == wParam) || (SIZE_MINIMIZED == wParam)) { active_ = false; this->OnSize()(*this, false); } else { active_ = true; this->OnSize()(*this, true); } break; case WM_GETMINMAXINFO: // Prevent the window from going smaller than some minimu size reinterpret_cast<MINMAXINFO*>(lParam)->ptMinTrackSize.x = 100; reinterpret_cast<MINMAXINFO*>(lParam)->ptMinTrackSize.y = 100; break; case WM_SETCURSOR: this->OnSetCursor()(*this); break; case WM_CHAR: this->OnChar()(*this, static_cast<wchar_t>(wParam)); break; case WM_INPUT: this->OnRawInput()(*this, reinterpret_cast<HRAWINPUT>(lParam)); break; #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) case WM_POINTERDOWN: { POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; ::ScreenToClient(this->HWnd(), &pt); this->OnPointerDown()(*this, int2(pt.x, pt.y), GET_POINTERID_WPARAM(wParam)); } break; case WM_POINTERUP: { POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; ::ScreenToClient(this->HWnd(), &pt); this->OnPointerUp()(*this, int2(pt.x, pt.y), GET_POINTERID_WPARAM(wParam)); } break; case WM_POINTERUPDATE: { POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; ::ScreenToClient(this->HWnd(), &pt); this->OnPointerUpdate()(*this, int2(pt.x, pt.y), GET_POINTERID_WPARAM(wParam), IS_POINTER_INCONTACT_WPARAM(wParam)); } break; case WM_POINTERWHEEL: { POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; ::ScreenToClient(this->HWnd(), &pt); this->OnPointerWheel()(*this, int2(pt.x, pt.y), GET_POINTERID_WPARAM(wParam), GET_WHEEL_DELTA_WPARAM(wParam)); } break; #elif (_WIN32_WINNT >= _WIN32_WINNT_WIN7) case WM_TOUCH: this->OnTouch()(*this, reinterpret_cast<HTOUCHINPUT>(lParam), LOWORD(wParam)); break; #endif case WM_CLOSE: this->OnClose()(*this); active_ = false; ready_ = false; closed_ = true; ::PostQuitMessage(0); return 0; } return default_wnd_proc_(hWnd, uMsg, wParam, lParam); }
LRESULT Window::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_ACTIVATE: if (WA_INACTIVE == LOWORD(wParam)) { this->OnActive(false); } else { this->OnActive(true); } break; case WM_ERASEBKGND: return 1; case WM_PAINT: this->OnPaint(); break; case WM_ENTERSIZEMOVE: // Previent rendering while moving / sizing this->OnEnterSizeMove(); break; case WM_EXITSIZEMOVE: this->OnExitSizeMove(); break; case WM_SIZE: // Check to see if we are losing or gaining our window. Set the // active flag to match if ((SIZE_MAXHIDE == wParam) || (SIZE_MINIMIZED == wParam)) { this->OnSize(false); } else { this->OnSize(true); } break; case WM_GETMINMAXINFO: // Prevent the window from going smaller than some minimu size reinterpret_cast<MINMAXINFO*>(lParam)->ptMinTrackSize.x = 100; reinterpret_cast<MINMAXINFO*>(lParam)->ptMinTrackSize.y = 100; break; case WM_SETCURSOR: this->OnSetCursor(); break; case WM_CHAR: this->OnChar(static_cast<wchar_t>(wParam)); break; case WM_KEYDOWN: this->OnKeyDown(static_cast<wchar_t>(wParam)); break; case WM_KEYUP: this->OnKeyUp( static_cast<wchar_t>(wParam)); break; case WM_LBUTTONDOWN: { uint32_t buttons = MB_Left; if (wParam & MK_RBUTTON) { buttons |= MB_Right; } if (wParam & MK_MBUTTON) { buttons |= MB_Middle; } if (wParam & MK_CONTROL) { buttons |= MB_Ctrl; } if (wParam & MK_SHIFT) { buttons |= MB_Shift; } this->OnMouseDown( buttons, Vec2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); } break; case WM_RBUTTONDOWN: { uint32_t buttons = MB_Right; if (wParam & MK_LBUTTON) { buttons |= MB_Left; } if (wParam & MK_MBUTTON) { buttons |= MB_Middle; } if (wParam & MK_CONTROL) { buttons |= MB_Ctrl; } if (wParam & MK_SHIFT) { buttons |= MB_Shift; } this->OnMouseDown(buttons, Vec2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); } break; case WM_MBUTTONDOWN: { uint32_t buttons = MB_Middle; if (wParam & MK_LBUTTON) { buttons |= MB_Left; } if (wParam & MK_RBUTTON) { buttons |= MB_Right; } if (wParam & MK_CONTROL) { buttons |= MB_Ctrl; } if (wParam & MK_SHIFT) { buttons |= MB_Shift; } this->OnMouseDown(buttons, Vec2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); } break; case WM_LBUTTONUP: { uint32_t buttons = MB_Left; if (wParam & MK_RBUTTON) { buttons |= MB_Right; } if (wParam & MK_MBUTTON) { buttons |= MB_Middle; } if (wParam & MK_CONTROL) { buttons |= MB_Ctrl; } if (wParam & MK_SHIFT) { buttons |= MB_Shift; } this->OnMouseUp(buttons, Vec2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); } break; case WM_RBUTTONUP: { uint32_t buttons = MB_Right; if (wParam & MK_LBUTTON) { buttons |= MB_Left; } if (wParam & MK_MBUTTON) { buttons |= MB_Middle; } if (wParam & MK_CONTROL) { buttons |= MB_Ctrl; } if (wParam & MK_SHIFT) { buttons |= MB_Shift; } this->OnMouseUp( buttons, Vec2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); } break; case WM_MBUTTONUP: { uint32_t buttons = MB_Middle; if (wParam & MK_LBUTTON) { buttons |= MB_Left; } if (wParam & MK_RBUTTON) { buttons |= MB_Right; } if (wParam & MK_CONTROL) { buttons |= MB_Ctrl; } if (wParam & MK_SHIFT) { buttons |= MB_Shift; } this->OnMouseUp(buttons, Vec2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); } break; case WM_MOUSEWHEEL: { uint32_t buttons = MB_None; if (GET_KEYSTATE_WPARAM(wParam) & MK_LBUTTON) { buttons |= MB_Left; } if (GET_KEYSTATE_WPARAM(wParam) & MK_RBUTTON) { buttons |= MB_Right; } if (GET_KEYSTATE_WPARAM(wParam) & MK_MBUTTON) { buttons |= MB_Middle; } if (GET_KEYSTATE_WPARAM(wParam) & MK_CONTROL) { buttons |= MB_Ctrl; } if (GET_KEYSTATE_WPARAM(wParam) & MK_SHIFT) { buttons |= MB_Shift; } this->OnMouseWheel(buttons, Vec2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)), GET_WHEEL_DELTA_WPARAM(wParam)); } break; case WM_MOUSEMOVE: { uint32_t buttons = MB_None; if (GET_KEYSTATE_WPARAM(wParam) & MK_LBUTTON) { buttons |= MB_Left; } if (GET_KEYSTATE_WPARAM(wParam) & MK_RBUTTON) { buttons |= MB_Right; } if (GET_KEYSTATE_WPARAM(wParam) & MK_MBUTTON) { buttons |= MB_Middle; } if (GET_KEYSTATE_WPARAM(wParam) & MK_CONTROL) { buttons |= MB_Ctrl; } if (GET_KEYSTATE_WPARAM(wParam) & MK_SHIFT) { buttons |= MB_Shift; } this->OnMouseOver( buttons, Vec2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); } break; case WM_CLOSE: this->OnClose(); closed_ = true; ::PostQuitMessage(0); return 0; } return default_wnd_proc_(hWnd, uMsg, wParam, lParam); }