1
0
Fork 0

Using SetProcessDpiAwarenessContext instead of QTAPI on Win10 above 1703

This commit is contained in:
gmh5225 2022-06-07 17:56:15 +08:00
parent f451111a2b
commit 25ef085966
No known key found for this signature in database
GPG Key ID: 3BBC731F40B2CEC1
1 changed files with 27 additions and 0 deletions

View File

@ -73,8 +73,35 @@ static bool isValidLocale(const QString & locale)
return false;
}
static void enableHighDpiScaling()
{
// https://www.vergiliusproject.com/kernels/x64/Windows%2010%20%7C%202016/2009%2020H2%20(October%202020%20Update)/_KUSER_SHARED_DATA
uint32_t NtBuildNumber = *(uint32_t*)(0x7FFE0000 + 0x260);
if(NtBuildNumber == 0 /* pre Windows-10 */ || NtBuildNumber < 15063)
{
// old windows version
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
}
else
{
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setprocessdpiawarenesscontext
static auto user32 = LoadLibraryW(L"user32.dll");
if(user32)
{
typedef BOOL(*pfnSetProcessDpiAwarenessContext)(int value);
static auto pSetProcessDpiAwarenessContext = (pfnSetProcessDpiAwarenessContext)GetProcAddress(user32, "SetProcessDpiAwarenessContext");
if(pSetProcessDpiAwarenessContext)
{
pSetProcessDpiAwarenessContext(/*DPI_AWARENESS_CONTEXT_SYSTEM_AWARE*/-2);
}
}
}
}
int main(int argc, char* argv[])
{
enableHighDpiScaling();
MyApplication application(argc, argv);
MainWindow::loadSelectedStyle(true);
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)