- 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
parent 38cff89a23
commit 51b3e4b335
No known key found for this signature in database
GPG key ID: 26A8ACCE97115EE0

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()