From 7652b321d063bc03099bac78fc1d4f91b1a19cc2 Mon Sep 17 00:00:00 2001 From: Triang3l Date: Sun, 13 Feb 2022 23:07:27 +0300 Subject: [PATCH] [UI] Fix Windows 10 1607+ DPI function loading --- src/xenia/ui/windowed_app_context_win.cc | 14 ++++++++++---- src/xenia/ui/windowed_app_context_win.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/xenia/ui/windowed_app_context_win.cc b/src/xenia/ui/windowed_app_context_win.cc index f9371304a..afee1a44f 100644 --- a/src/xenia/ui/windowed_app_context_win.cc +++ b/src/xenia/ui/windowed_app_context_win.cc @@ -22,6 +22,9 @@ Win32WindowedAppContext::~Win32WindowedAppContext() { if (pending_functions_hwnd_) { DestroyWindow(pending_functions_hwnd_); } + if (user32_module_) { + FreeLibrary(user32_module_); + } if (shcore_module_) { FreeLibrary(shcore_module_); } @@ -38,25 +41,28 @@ bool Win32WindowedAppContext::Initialize() { (*reinterpret_cast( &per_monitor_dpi_v1_api_.get_dpi_for_monitor) = GetProcAddress(shcore_module_, "GetDpiForMonitor")) != nullptr; + } + user32_module_ = LoadLibraryW(L"user32.dll"); + if (user32_module_) { per_monitor_dpi_v2_api_available_ = true; per_monitor_dpi_v2_api_available_ &= (*reinterpret_cast( &per_monitor_dpi_v2_api_.adjust_window_rect_ex_for_dpi) = - GetProcAddress(shcore_module_, "AdjustWindowRectExForDpi")) != + GetProcAddress(user32_module_, "AdjustWindowRectExForDpi")) != nullptr; per_monitor_dpi_v2_api_available_ &= (*reinterpret_cast( &per_monitor_dpi_v2_api_.enable_non_client_dpi_scaling) = - GetProcAddress(shcore_module_, "EnableNonClientDpiScaling")) != + GetProcAddress(user32_module_, "EnableNonClientDpiScaling")) != nullptr; per_monitor_dpi_v2_api_available_ &= (*reinterpret_cast( &per_monitor_dpi_v2_api_.get_dpi_for_system) = - GetProcAddress(shcore_module_, "GetDpiForSystem")) != nullptr; + GetProcAddress(user32_module_, "GetDpiForSystem")) != nullptr; per_monitor_dpi_v2_api_available_ &= (*reinterpret_cast( &per_monitor_dpi_v2_api_.get_dpi_for_window) = - GetProcAddress(shcore_module_, "GetDpiForWindow")) != nullptr; + GetProcAddress(user32_module_, "GetDpiForWindow")) != nullptr; } // Create the message-only window for executing pending functions - using a diff --git a/src/xenia/ui/windowed_app_context_win.h b/src/xenia/ui/windowed_app_context_win.h index 08e70e662..5bf4d43c5 100644 --- a/src/xenia/ui/windowed_app_context_win.h +++ b/src/xenia/ui/windowed_app_context_win.h @@ -97,6 +97,7 @@ class Win32WindowedAppContext final : public WindowedAppContext { int show_cmd_; HMODULE shcore_module_ = nullptr; + HMODULE user32_module_ = nullptr; PerMonitorDpiV1Api per_monitor_dpi_v1_api_ = {}; PerMonitorDpiV2Api per_monitor_dpi_v2_api_ = {}; bool per_monitor_dpi_v1_api_available_ = false;