Better DPI awareness

This commit is contained in:
Maurice Heumann 2023-01-31 19:14:02 +01:00
parent 924e476328
commit c25ad4dcb8
2 changed files with 35 additions and 6 deletions

View File

@ -174,6 +174,8 @@ namespace
void enable_dpi_awareness() void enable_dpi_awareness()
{ {
const utils::nt::library user32{"user32.dll"}; const utils::nt::library user32{"user32.dll"};
{
const auto set_dpi = user32 const auto set_dpi = user32
? user32.get_proc<BOOL(WINAPI*)(DPI_AWARENESS_CONTEXT)>( ? user32.get_proc<BOOL(WINAPI*)(DPI_AWARENESS_CONTEXT)>(
"SetProcessDpiAwarenessContext") "SetProcessDpiAwarenessContext")
@ -181,6 +183,32 @@ namespace
if (set_dpi) if (set_dpi)
{ {
set_dpi(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); set_dpi(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
return;
}
}
{
const utils::nt::library shcore{"shcore.dll"};
const auto set_dpi = shcore
? shcore.get_proc<HRESULT(WINAPI*)(PROCESS_DPI_AWARENESS)>(
"SetProcessDpiAwareness")
: nullptr;
if (set_dpi)
{
set_dpi(PROCESS_PER_MONITOR_DPI_AWARE);
return;
}
}
{
const auto set_dpi = user32
? user32.get_proc<BOOL(WINAPI*)()>(
"SetProcessDPIAware")
: nullptr;
if (set_dpi)
{
set_dpi();
}
} }
} }

View File

@ -50,6 +50,7 @@
#include <atlsafe.h> #include <atlsafe.h>
#include <iphlpapi.h> #include <iphlpapi.h>
#include <wincrypt.h> #include <wincrypt.h>
#include <shellscalingapi.h>
// min and max is required by gdi, therefore NOMINMAX won't work // min and max is required by gdi, therefore NOMINMAX won't work
#ifdef max #ifdef max