From c25ad4dcb86521ab59bcdfffa584c4298ac6f9b3 Mon Sep 17 00:00:00 2001 From: Maurice Heumann Date: Tue, 31 Jan 2023 19:14:02 +0100 Subject: [PATCH] Better DPI awareness --- src/client/main.cpp | 40 ++++++++++++++++++++++++++++++++------ src/client/std_include.hpp | 1 + 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/client/main.cpp b/src/client/main.cpp index 5909e93c..193c7b59 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -174,13 +174,41 @@ namespace void enable_dpi_awareness() { const utils::nt::library user32{"user32.dll"}; - const auto set_dpi = user32 - ? user32.get_proc( - "SetProcessDpiAwarenessContext") - : nullptr; - if (set_dpi) + { - set_dpi(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); + const auto set_dpi = user32 + ? user32.get_proc( + "SetProcessDpiAwarenessContext") + : nullptr; + if (set_dpi) + { + 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( + "SetProcessDpiAwareness") + : nullptr; + if (set_dpi) + { + set_dpi(PROCESS_PER_MONITOR_DPI_AWARE); + return; + } + } + + { + const auto set_dpi = user32 + ? user32.get_proc( + "SetProcessDPIAware") + : nullptr; + if (set_dpi) + { + set_dpi(); + } } } diff --git a/src/client/std_include.hpp b/src/client/std_include.hpp index a9c9d402..a29aa2a6 100644 --- a/src/client/std_include.hpp +++ b/src/client/std_include.hpp @@ -50,6 +50,7 @@ #include #include #include +#include // min and max is required by gdi, therefore NOMINMAX won't work #ifdef max