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
This commit is contained in:
Dustin Howett 2020-11-19 23:21:37 +00:00
parent ee1c1011f7
commit 1e42bc8e4f
7 changed files with 10 additions and 116 deletions

View file

@ -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();
}
}

View file

@ -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;

View file

@ -352,8 +352,6 @@ void Window::_UpdateSystemMetrics() const
SendMessageW(hWnd, WM_SETHOTKEY, gci.GetHotKey(), 0);
}
ServiceLocator::LocateHighDpiApi<WindowDpiApi>()->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).

View file

@ -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;
}

View file

@ -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);

View file

@ -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<WindowDpiApi>()->GetWindowDPI(hWnd);
int const dpi = ServiceLocator::LocateHighDpiApi<WindowDpiApi>()->GetDpiForWindow(hWnd);
if (dpi == ServiceLocator::LocateGlobals().dpi)
{
_HandleWindowPosChanged(lParam);

View file

@ -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)
{