From c0d5d119424c93f5eca60c80cceb6066ca1fe905 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 10 Oct 2022 08:53:23 -0700 Subject: [PATCH 1/2] SetThreadDpiAwareness for host error dialog --- src/native/corehost/apphost/apphost.windows.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/native/corehost/apphost/apphost.windows.cpp b/src/native/corehost/apphost/apphost.windows.cpp index 43abe909e776f..24b2fc2f17a4f 100644 --- a/src/native/corehost/apphost/apphost.windows.cpp +++ b/src/native/corehost/apphost/apphost.windows.cpp @@ -323,6 +323,20 @@ namespace trace::verbose(_X("Showing error dialog for application: '%s' - error code: 0x%x - url: '%s' - details: %s"), executable_name, error_code, url.c_str(), details.c_str()); + HMODULE user32 = ::LoadLibraryExW(L"user32.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); + if (user32 != nullptr) + { + typedef DPI_AWARENESS_CONTEXT(WINAPI* set_thread_dpi)(DPI_AWARENESS_CONTEXT context); + set_thread_dpi set_thread_dpi_func = (set_thread_dpi)::GetProcAddress(user32, "SetThreadDpiAwarenessContext"); + + // Since this is only for errors shown when the process is about to exit, we + // skip resetting to the previous context to minimize impact on apphost size + if (set_thread_dpi_func != nullptr) + (void) set_thread_dpi_func(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); + + ::FreeLibrary(user32); + } + if (enable_visual_styles()) { // Task dialog requires enabling visual styles From 548b7656b021736cec0ad951dd67100101277ef2 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Fri, 10 Feb 2023 09:17:51 -0800 Subject: [PATCH 2/2] Update src/native/corehost/apphost/apphost.windows.cpp Co-authored-by: Aaron Robinson --- src/native/corehost/apphost/apphost.windows.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/corehost/apphost/apphost.windows.cpp b/src/native/corehost/apphost/apphost.windows.cpp index 24b2fc2f17a4f..e0dd4d7f52ada 100644 --- a/src/native/corehost/apphost/apphost.windows.cpp +++ b/src/native/corehost/apphost/apphost.windows.cpp @@ -326,7 +326,7 @@ namespace HMODULE user32 = ::LoadLibraryExW(L"user32.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); if (user32 != nullptr) { - typedef DPI_AWARENESS_CONTEXT(WINAPI* set_thread_dpi)(DPI_AWARENESS_CONTEXT context); + using set_thread_dpi = DPI_AWARENESS_CONTEXT(WINAPI*)(DPI_AWARENESS_CONTEXT context); set_thread_dpi set_thread_dpi_func = (set_thread_dpi)::GetProcAddress(user32, "SetThreadDpiAwarenessContext"); // Since this is only for errors shown when the process is about to exit, we