2026-04-13 19:37:10 +08:00
|
|
|
#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<EnableNonClientDpiScalingFn>(
|
|
|
|
|
GetProcAddress(user32, "EnableNonClientDpiScaling"));
|
|
|
|
|
if (enableNonClientDpiScaling != nullptr) {
|
|
|
|
|
enableNonClientDpiScaling(hwnd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Application* WindowMessageDispatcher::GetApplicationFromWindow(HWND hwnd) {
|
|
|
|
|
return reinterpret_cast<Application*>(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<CREATESTRUCTW*>(lParam);
|
|
|
|
|
auto* application = reinterpret_cast<Application*>(createStruct->lpCreateParams);
|
|
|
|
|
SetWindowLongPtrW(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(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<UINT>(LOWORD(wParam)),
|
|
|
|
|
*reinterpret_cast<const RECT*>(lParam));
|
2026-04-13 23:09:02 +08:00
|
|
|
if (application.m_renderReady) {
|
|
|
|
|
application.RenderFrame();
|
|
|
|
|
}
|
2026-04-13 19:37:10 +08:00
|
|
|
outResult = 0;
|
|
|
|
|
return true;
|
|
|
|
|
case WM_ENTERSIZEMOVE:
|
|
|
|
|
application.OnEnterSizeMove();
|
|
|
|
|
outResult = 0;
|
|
|
|
|
return true;
|
|
|
|
|
case WM_EXITSIZEMOVE:
|
|
|
|
|
application.OnExitSizeMove();
|
2026-04-13 23:09:02 +08:00
|
|
|
if (application.m_renderReady) {
|
|
|
|
|
application.RenderFrame();
|
|
|
|
|
}
|
2026-04-13 19:37:10 +08:00
|
|
|
outResult = 0;
|
|
|
|
|
return true;
|
|
|
|
|
case WM_SIZE:
|
|
|
|
|
if (wParam != SIZE_MINIMIZED) {
|
2026-04-13 23:09:02 +08:00
|
|
|
application.OnResize(
|
|
|
|
|
static_cast<UINT>(LOWORD(lParam)),
|
|
|
|
|
static_cast<UINT>(HIWORD(lParam)));
|
|
|
|
|
if (application.m_renderReady) {
|
|
|
|
|
application.RenderFrame();
|
|
|
|
|
}
|
2026-04-13 19:37:10 +08:00
|
|
|
}
|
|
|
|
|
outResult = 0;
|
|
|
|
|
return true;
|
|
|
|
|
case WM_PAINT:
|
|
|
|
|
application.OnPaintMessage();
|
|
|
|
|
outResult = 0;
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace XCEngine::UI::Editor::Host
|