| @@ -373,6 +373,32 @@ static EnableNonClientDPIScalingFunc enableNonClientDPIScaling | |||||
| static bool hasCheckedForDPIAwareness = false; | static bool hasCheckedForDPIAwareness = false; | ||||
| static void loadDPIAwarenessFunctions() | |||||
| { | |||||
| setProcessDPIAware = (SetProcessDPIAwareFunc) getUser32Function ("SetProcessDPIAware"); | |||||
| constexpr auto shcore = "SHCore.dll"; | |||||
| LoadLibraryA (shcore); | |||||
| const auto shcoreModule = GetModuleHandleA (shcore); | |||||
| if (shcoreModule == nullptr) | |||||
| return; | |||||
| getDPIForMonitor = (GetDPIForMonitorFunc) GetProcAddress (shcoreModule, "GetDpiForMonitor"); | |||||
| setProcessDPIAwareness = (SetProcessDPIAwarenessFunc) GetProcAddress (shcoreModule, "SetProcessDpiAwareness"); | |||||
| #if JUCE_WIN_PER_MONITOR_DPI_AWARE | |||||
| getDPIForWindow = (GetDPIForWindowFunc) getUser32Function ("GetDpiForWindow"); | |||||
| getProcessDPIAwareness = (GetProcessDPIAwarenessFunc) GetProcAddress (shcoreModule, "GetProcessDpiAwareness"); | |||||
| getWindowDPIAwarenessContext = (GetWindowDPIAwarenessContextFunc) getUser32Function ("GetWindowDpiAwarenessContext"); | |||||
| setThreadDPIAwarenessContext = (SetThreadDPIAwarenessContextFunc) getUser32Function ("SetThreadDpiAwarenessContext"); | |||||
| getThreadDPIAwarenessContext = (GetThreadDPIAwarenessContextFunc) getUser32Function ("GetThreadDpiAwarenessContext"); | |||||
| getAwarenessFromDPIAwarenessContext = (GetAwarenessFromDpiAwarenessContextFunc) getUser32Function ("GetAwarenessFromDpiAwarenessContext"); | |||||
| setProcessDPIAwarenessContext = (SetProcessDPIAwarenessContextFunc) getUser32Function ("SetProcessDpiAwarenessContext"); | |||||
| enableNonClientDPIScaling = (EnableNonClientDPIScalingFunc) getUser32Function ("EnableNonClientDpiScaling"); | |||||
| #endif | |||||
| } | |||||
| static void setDPIAwareness() | static void setDPIAwareness() | ||||
| { | { | ||||
| if (hasCheckedForDPIAwareness) | if (hasCheckedForDPIAwareness) | ||||
| @@ -383,45 +409,19 @@ static void setDPIAwareness() | |||||
| if (! JUCEApplicationBase::isStandaloneApp()) | if (! JUCEApplicationBase::isStandaloneApp()) | ||||
| return; | return; | ||||
| const auto shcore = "SHCore.dll"; | |||||
| LoadLibraryA (shcore); | |||||
| const auto shcoreModule = GetModuleHandleA (shcore); | |||||
| if (shcoreModule != nullptr) | |||||
| { | |||||
| getDPIForMonitor = (GetDPIForMonitorFunc) GetProcAddress (shcoreModule, "GetDpiForMonitor"); | |||||
| #if JUCE_WIN_PER_MONITOR_DPI_AWARE | |||||
| getDPIForWindow = (GetDPIForWindowFunc) getUser32Function ("GetDpiForWindow"); | |||||
| getProcessDPIAwareness = (GetProcessDPIAwarenessFunc) GetProcAddress (shcoreModule, "GetProcessDpiAwareness"); | |||||
| getWindowDPIAwarenessContext = (GetWindowDPIAwarenessContextFunc) getUser32Function ("GetWindowDpiAwarenessContext"); | |||||
| setThreadDPIAwarenessContext = (SetThreadDPIAwarenessContextFunc) getUser32Function ("SetThreadDpiAwarenessContext"); | |||||
| getThreadDPIAwarenessContext = (GetThreadDPIAwarenessContextFunc) getUser32Function ("GetThreadDpiAwarenessContext"); | |||||
| getAwarenessFromDPIAwarenessContext = (GetAwarenessFromDpiAwarenessContextFunc) getUser32Function ("GetAwarenessFromDpiAwarenessContext"); | |||||
| setProcessDPIAwareness = (SetProcessDPIAwarenessFunc) GetProcAddress (shcoreModule, "SetProcessDpiAwareness"); | |||||
| setProcessDPIAwarenessContext = (SetProcessDPIAwarenessContextFunc) getUser32Function ("SetProcessDpiAwarenessContext"); | |||||
| if (setProcessDPIAwarenessContext != nullptr | |||||
| && setProcessDPIAwarenessContext (DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)) | |||||
| return; | |||||
| enableNonClientDPIScaling = (EnableNonClientDPIScalingFunc) getUser32Function ("EnableNonClientDpiScaling"); | |||||
| if (setProcessDPIAwareness != nullptr && enableNonClientDPIScaling != nullptr | |||||
| && SUCCEEDED (setProcessDPIAwareness (DPI_Awareness::DPI_Awareness_Per_Monitor_Aware))) | |||||
| return; | |||||
| #endif | |||||
| loadDPIAwarenessFunctions(); | |||||
| if (setProcessDPIAwareness == nullptr) | |||||
| setProcessDPIAwareness = (SetProcessDPIAwarenessFunc) GetProcAddress (shcoreModule, "SetProcessDpiAwareness"); | |||||
| if (setProcessDPIAwarenessContext != nullptr | |||||
| && setProcessDPIAwarenessContext (DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)) | |||||
| return; | |||||
| if (setProcessDPIAwareness != nullptr && getDPIForMonitor != nullptr | |||||
| && SUCCEEDED (setProcessDPIAwareness (DPI_Awareness::DPI_Awareness_System_Aware))) | |||||
| return; | |||||
| } | |||||
| if (setProcessDPIAwareness != nullptr && enableNonClientDPIScaling != nullptr | |||||
| && SUCCEEDED (setProcessDPIAwareness (DPI_Awareness::DPI_Awareness_Per_Monitor_Aware))) | |||||
| return; | |||||
| // fallback for pre Windows 8.1 - equivalent to Process_System_DPI_Aware | |||||
| setProcessDPIAware = (SetProcessDPIAwareFunc) getUser32Function ("SetProcessDPIAware"); | |||||
| if (setProcessDPIAwareness != nullptr && getDPIForMonitor != nullptr | |||||
| && SUCCEEDED (setProcessDPIAwareness (DPI_Awareness::DPI_Awareness_System_Aware))) | |||||
| return; | |||||
| if (setProcessDPIAware != nullptr) | if (setProcessDPIAware != nullptr) | ||||
| setProcessDPIAware(); | setProcessDPIAware(); | ||||
| @@ -436,6 +436,9 @@ static bool isPerMonitorDPIAwareProcess() | |||||
| { | { | ||||
| setDPIAwareness(); | setDPIAwareness(); | ||||
| if (! JUCEApplication::isStandaloneApp()) | |||||
| return false; | |||||
| if (getProcessDPIAwareness == nullptr) | if (getProcessDPIAwareness == nullptr) | ||||
| return false; | return false; | ||||