- dynamically import GetDpiForWindow from USER32.dll, else return a default value

This commit is contained in:
Rachael Alexanderson 2024-04-21 07:09:00 -04:00 committed by Christoph Oelckers
parent 1fe6556e6e
commit 744e67e02b

View file

@ -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<GetDpiForWindow_t>(GetProcAddress(hMod, "GetDpiForWindow"));
}
if (pGetDpiForWindow)
return pGetDpiForWindow(WindowHandle) / 96.0;
else
return 1.0;
}
std::string Win32Window::GetClipboardText()