From 744e67e02b479dbcf4b66ac809f08dc2a18adcd7 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sun, 21 Apr 2024 07:09:00 -0400 Subject: [PATCH] - dynamically import GetDpiForWindow from USER32.dll, else return a default value --- libraries/ZWidget/src/window/win32/win32window.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libraries/ZWidget/src/window/win32/win32window.cpp b/libraries/ZWidget/src/window/win32/win32window.cpp index 8a1fda50c0..64d4701ed5 100644 --- a/libraries/ZWidget/src/window/win32/win32window.cpp +++ b/libraries/ZWidget/src/window/win32/win32window.cpp @@ -271,9 +271,20 @@ int Win32Window::GetPixelHeight() const return box.bottom; } +typedef UINT(WINAPI* GetDpiForWindow_t)(HWND); double Win32Window::GetDpiScale() const { - return GetDpiForWindow(WindowHandle) / 96.0; + static GetDpiForWindow_t pGetDpiForWindow = nullptr; + if (!pGetDpiForWindow) + { + HMODULE hMod = LoadLibrary(TEXT("User32.dll")); + pGetDpiForWindow = reinterpret_cast(GetProcAddress(hMod, "GetDpiForWindow")); + } + + if (pGetDpiForWindow) + return pGetDpiForWindow(WindowHandle) / 96.0; + else + return 1.0; } std::string Win32Window::GetClipboardText()