#include "WindowMessageDispatcher.h" #include "../Application.h" namespace XCEngine::UI::Editor::Host { void TryEnableNonClientDpiScaling(HWND hwnd) { if (hwnd == nullptr) { return; } const HMODULE user32 = GetModuleHandleW(L"user32.dll"); if (user32 == nullptr) { return; } using EnableNonClientDpiScalingFn = BOOL(WINAPI*)(HWND); const auto enableNonClientDpiScaling = reinterpret_cast( GetProcAddress(user32, "EnableNonClientDpiScaling")); if (enableNonClientDpiScaling != nullptr) { enableNonClientDpiScaling(hwnd); } } Application* WindowMessageDispatcher::GetApplicationFromWindow(HWND hwnd) { return reinterpret_cast(GetWindowLongPtrW(hwnd, GWLP_USERDATA)); } bool WindowMessageDispatcher::TryHandleNonClientCreate( HWND hwnd, UINT message, LPARAM lParam, LRESULT& outResult) { if (message != WM_NCCREATE) { return false; } TryEnableNonClientDpiScaling(hwnd); const auto* createStruct = reinterpret_cast(lParam); auto* application = reinterpret_cast(createStruct->lpCreateParams); SetWindowLongPtrW(hwnd, GWLP_USERDATA, reinterpret_cast(application)); outResult = TRUE; return true; } bool WindowMessageDispatcher::TryDispatch( Application& application, UINT message, WPARAM wParam, LPARAM lParam, LRESULT& outResult) { switch (message) { case WM_SETCURSOR: if (LOWORD(lParam) == HTCLIENT && application.ApplyCurrentCursor()) { outResult = TRUE; return true; } return false; case WM_DPICHANGED: if (lParam == 0) { return false; } application.OnDpiChanged( static_cast(LOWORD(wParam)), *reinterpret_cast(lParam)); if (application.m_renderReady) { application.RenderFrame(); } outResult = 0; return true; case WM_ENTERSIZEMOVE: application.OnEnterSizeMove(); outResult = 0; return true; case WM_EXITSIZEMOVE: application.OnExitSizeMove(); if (application.m_renderReady) { application.RenderFrame(); } outResult = 0; return true; case WM_SIZE: if (wParam != SIZE_MINIMIZED) { application.OnResize( static_cast(LOWORD(lParam)), static_cast(HIWORD(lParam))); if (application.m_renderReady) { application.RenderFrame(); } } outResult = 0; return true; case WM_PAINT: application.OnPaintMessage(); outResult = 0; return true; default: return false; } } } // namespace XCEngine::UI::Editor::Host