From 1e42bc8e4f1ddaa2157a1f65fe46182c39ca4582 Mon Sep 17 00:00:00 2001 From: Dustin Howett Date: Thu, 19 Nov 2020 23:21:37 +0000 Subject: [PATCH] Merged PR 5421982: Reflect OS build changes [Git2Git] Git Train: Merge of building/rs_onecore_dep_uxp/201117-2002 into official/rs_onecore_dep_uxp Retrieved from https://microsoft.visualstudio.com os.2020 OS official/rs_onecore_dep_uxp 526043ab6050397506b3cdb77e6a43b5ca9a2e9a Related work items: MSFT-29990377 --- src/host/srvinit.cpp | 4 - src/interactivity/inc/IHighDpiApi.hpp | 1 - src/interactivity/win32/window.cpp | 2 - src/interactivity/win32/windowdpiapi.cpp | 101 ++--------------------- src/interactivity/win32/windowdpiapi.hpp | 5 +- src/interactivity/win32/windowproc.cpp | 4 +- src/tools/pixels/main.cpp | 9 +- 7 files changed, 10 insertions(+), 116 deletions(-) diff --git a/src/host/srvinit.cpp b/src/host/srvinit.cpp index adead2a1d..6bfe328b3 100644 --- a/src/host/srvinit.cpp +++ b/src/host/srvinit.cpp @@ -177,10 +177,6 @@ static bool s_IsOnDesktop() { // Fallback to per-monitor aware V1 if the API isn't available. LOG_IF_FAILED(pHighDpiApi->SetProcessPerMonitorDpiAwareness()); - - // Allow child dialogs (i.e. Properties and Find) to scale automatically based on DPI if we're currently DPI aware. - // Note that we don't need to do this if we're PMv2. - pHighDpiApi->EnablePerMonitorDialogScaling(); } } diff --git a/src/interactivity/inc/IHighDpiApi.hpp b/src/interactivity/inc/IHighDpiApi.hpp index b748c33c0..8b620b2c1 100644 --- a/src/interactivity/inc/IHighDpiApi.hpp +++ b/src/interactivity/inc/IHighDpiApi.hpp @@ -21,7 +21,6 @@ namespace Microsoft::Console::Interactivity public: virtual BOOL SetProcessDpiAwarenessContext() = 0; [[nodiscard]] virtual HRESULT SetProcessPerMonitorDpiAwareness() = 0; - virtual BOOL EnablePerMonitorDialogScaling() = 0; virtual ~IHighDpiApi() = 0; diff --git a/src/interactivity/win32/window.cpp b/src/interactivity/win32/window.cpp index 3b2ce7828..8ddb5abfa 100644 --- a/src/interactivity/win32/window.cpp +++ b/src/interactivity/win32/window.cpp @@ -352,8 +352,6 @@ void Window::_UpdateSystemMetrics() const SendMessageW(hWnd, WM_SETHOTKEY, gci.GetHotKey(), 0); } - ServiceLocator::LocateHighDpiApi()->EnableChildWindowDpiMessage(_hWnd, TRUE /*fEnable*/); - // Post a window size update so that the new console window will size itself correctly once it's up and // running. This works around chicken & egg cases involving window size calculations having to do with font // sizes, DPI, and non-primary monitors (see MSFT #2367234). diff --git a/src/interactivity/win32/windowdpiapi.cpp b/src/interactivity/win32/windowdpiapi.cpp index 85ea5a53b..e18ec3d52 100644 --- a/src/interactivity/win32/windowdpiapi.cpp +++ b/src/interactivity/win32/windowdpiapi.cpp @@ -21,39 +21,6 @@ BOOL WindowDpiApi::SetProcessDpiAwarenessContext() return SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); } -BOOL WindowDpiApi::EnablePerMonitorDialogScaling() -{ -#ifdef CON_DPIAPI_INDIRECT - if (_hUser32 != nullptr) - { - static bool fTried = false; - static FARPROC pfnFunc = nullptr; - - if (!fTried) - { - pfnFunc = GetProcAddress(_hUser32, "EnablePerMonitorDialogScaling"); - - if (pfnFunc == nullptr) - { - // If retrieve by name fails, we have to get it by the ordinal because it was made a secret. - pfnFunc = GetProcAddress(_hUser32, MAKEINTRESOURCEA(2577)); - } - - fTried = true; - } - - if (pfnFunc != nullptr) - { - return (BOOL)pfnFunc(); - } - } - - return FALSE; -#else - return EnablePerMonitorDialogScaling(); -#endif -} - #pragma endregion BOOL WindowDpiApi::SetProcessDpiAwarenessContext(_In_ DPI_AWARENESS_CONTEXT dpiContext) @@ -81,42 +48,7 @@ BOOL WindowDpiApi::SetProcessDpiAwarenessContext(_In_ DPI_AWARENESS_CONTEXT dpiC return FALSE; #else - return EnableChildWindowDpiMessage(dpiContext); -#endif -} - -BOOL WindowDpiApi::EnableChildWindowDpiMessage(const HWND hwnd, const BOOL fEnable) -{ -#ifdef CON_DPIAPI_INDIRECT - if (_hUser32 != nullptr) - { - typedef BOOL(WINAPI * PfnEnableChildWindowDpiMessage)(HWND hwnd, BOOL fEnable); - - static bool fTried = false; - static PfnEnableChildWindowDpiMessage pfn = nullptr; - - if (!fTried) - { - pfn = (PfnEnableChildWindowDpiMessage)GetProcAddress(_hUser32, "EnableChildWindowDpiMessage"); - - if (pfn == nullptr) - { - // If that fails, we have to get it by the ordinal because it was made a secret in RS1. - pfn = (PfnEnableChildWindowDpiMessage)GetProcAddress(_hUser32, MAKEINTRESOURCEA(2704)); - } - - fTried = true; - } - - if (pfn != nullptr) - { - return pfn(hwnd, fEnable); - } - } - - return FALSE; -#else - return EnableChildWindowDpiMessage(hwnd, fEnable); + return SetProcessDpiAwarenessContext(dpiContext); #endif } @@ -136,15 +68,8 @@ BOOL WindowDpiApi::AdjustWindowRectExForDpi(_Inout_ LPRECT const lpRect, if (!fTried) { - // Try to retrieve it the RS1 way first pfn = (PfnAdjustWindowRectExForDpi)GetProcAddress(_hUser32, "AdjustWindowRectExForDpi"); - if (pfn == nullptr) - { - // If that fails, we have to get it by the ordinal because it was made a secret in TH/TH2. - pfn = (PfnAdjustWindowRectExForDpi)GetProcAddress(_hUser32, MAKEINTRESOURCEA(2580)); - } - fTried = true; } @@ -160,25 +85,19 @@ BOOL WindowDpiApi::AdjustWindowRectExForDpi(_Inout_ LPRECT const lpRect, #endif } -int WindowDpiApi::GetWindowDPI(const HWND hwnd) +int WindowDpiApi::GetDpiForWindow(const HWND hwnd) { #ifdef CON_DPIAPI_INDIRECT if (_hUser32 != nullptr) { - typedef int(WINAPI * PfnGetWindowDPI)(HWND hwnd); + typedef int(WINAPI * PfnGetDpiForWindow)(HWND hwnd); static bool fTried = false; - static PfnGetWindowDPI pfn = nullptr; + static PfnGetDpiForWindow pfn = nullptr; if (!fTried) { - pfn = (PfnGetWindowDPI)GetProcAddress(_hUser32, "GetWindowDPI"); - - if (pfn == nullptr) - { - // If that fails, we have to get it by the ordinal because it was made a secret in RS1. - pfn = (PfnGetWindowDPI)GetProcAddress(_hUser32, MAKEINTRESOURCEA(2707)); - } + pfn = (PfnGetDpiForWindow)GetProcAddress(_hUser32, "GetDpiForWindow"); fTried = true; } @@ -191,7 +110,6 @@ int WindowDpiApi::GetWindowDPI(const HWND hwnd) return USER_DEFAULT_SCREEN_DPI; #else - // GetDpiForWindow is the public API version (as of RS1) of GetWindowDPI return GetDpiForWindow(hwnd); #endif } @@ -208,14 +126,7 @@ int WindowDpiApi::GetSystemMetricsForDpi(const int nIndex, const UINT dpi) if (!fTried) { - // First try the TH1/TH2 name of the function. - pfn = (PfnGetDpiMetrics)GetProcAddress(_hUser32, "GetDpiMetrics"); - - if (pfn == nullptr) - { - // If not, then try the RS1 name of the function. - pfn = (PfnGetDpiMetrics)GetProcAddress(_hUser32, "GetSystemMetricsForDpi"); - } + pfn = (PfnGetDpiMetrics)GetProcAddress(_hUser32, "GetSystemMetricsForDpi"); fTried = true; } diff --git a/src/interactivity/win32/windowdpiapi.hpp b/src/interactivity/win32/windowdpiapi.hpp index 4b5497ff2..b3bb9cad8 100644 --- a/src/interactivity/win32/windowdpiapi.hpp +++ b/src/interactivity/win32/windowdpiapi.hpp @@ -51,19 +51,16 @@ namespace Microsoft::Console::Interactivity::Win32 // IHighDpi Interface BOOL SetProcessDpiAwarenessContext(); [[nodiscard]] HRESULT SetProcessPerMonitorDpiAwareness(); - BOOL EnablePerMonitorDialogScaling(); // Module-internal Functions BOOL SetProcessDpiAwarenessContext(_In_ DPI_AWARENESS_CONTEXT dpiContext); - BOOL EnableChildWindowDpiMessage(const HWND hwnd, - const BOOL fEnable); BOOL AdjustWindowRectExForDpi(_Inout_ LPRECT const lpRect, const DWORD dwStyle, const BOOL bMenu, const DWORD dwExStyle, const UINT dpi); - int GetWindowDPI(const HWND hwnd); + int GetDpiForWindow(const HWND hwnd); int GetSystemMetricsForDpi(const int nIndex, const UINT dpi); diff --git a/src/interactivity/win32/windowproc.cpp b/src/interactivity/win32/windowproc.cpp index d20bdc845..e423cc2ea 100644 --- a/src/interactivity/win32/windowproc.cpp +++ b/src/interactivity/win32/windowproc.cpp @@ -101,7 +101,7 @@ using namespace Microsoft::Console::Types; // First get the new DPI and update all the scaling factors in the console that are affected. - // NOTE: GetWindowDpi and/or GetDpiForWindow can be *WRONG* at this point in time depending on monitor configuration. + // NOTE: GetDpiForWindow can be *WRONG* at this point in time depending on monitor configuration. // They won't be correct until the window is actually shown. So instead of using those APIs, figure out the DPI // based on the rectangle that is about to be shown using the nearest monitor. @@ -465,7 +465,7 @@ using namespace Microsoft::Console::Types; // which will have a better suggested rectangle than this one. // NOTE: This stopped being possible in RS4 as the DPI now changes when and only when // we receive WM_DPICHANGED. We keep this check around so that we perform better downlevel. - int const dpi = ServiceLocator::LocateHighDpiApi()->GetWindowDPI(hWnd); + int const dpi = ServiceLocator::LocateHighDpiApi()->GetDpiForWindow(hWnd); if (dpi == ServiceLocator::LocateGlobals().dpi) { _HandleWindowPosChanged(lParam); diff --git a/src/tools/pixels/main.cpp b/src/tools/pixels/main.cpp index 3f9290695..c64be1fc5 100644 --- a/src/tools/pixels/main.cpp +++ b/src/tools/pixels/main.cpp @@ -181,14 +181,7 @@ int __cdecl wmain(int /*argc*/, WCHAR* /*argv*/[]) if (hUser32 != nullptr) { - // First try the TH1/TH2 name of the function. - PfnGetDpiMetrics pfn = (PfnGetDpiMetrics)GetProcAddress(hUser32, "GetDpiMetrics"); - - if (pfn == nullptr) - { - // If not, then try the RS1 name of the function. - pfn = (PfnGetDpiMetrics)GetProcAddress(hUser32, "GetSystemMetricsForDpi"); - } + pfn = (PfnGetDpiMetrics)GetProcAddress(hUser32, "GetSystemMetricsForDpi"); if (pfn != nullptr) {