@joebigelow / wix-1 / commits / 1f85dac5

Fix bug where theme window didn't enlarge client area for default DPI.

Sean Hall committed Jun 4, 2021 at 13:38 UTC 1f85dac530dee933457e99438fd1c82485a2a48e
1 file changed +33 -9
src/libs/dutil/WixToolset.DUtil/thmutil.cpp
+33 -9
@@ -526,6 +526,12 @@ static void ScaleTheme(
526 __in BOOL fMenu,
527 __in DWORD dwExStyle
528 );
529 +static void AdjustThemeWindowRect(
530 + __in THEME* pTheme,
531 + __in DWORD dwStyle,
532 + __in BOOL fMenu,
533 + __in DWORD dwExStyle
534 + );
535 static void ScaleControls(
536 __in THEME* pTheme,
537 __in DWORD cControls,
@@ -809,6 +815,7 @@ DAPI_(HRESULT) ThemeCreateParentWindow(
815 RECT* pMonitorRect = NULL;
816 HMENU hMenu = NULL;
817 HWND hWnd = NULL;
818 + BOOL fScaledTheme = FALSE;
819
820 if (pTheme->hwndParent)
821 {
@@ -826,6 +833,7 @@ DAPI_(HRESULT) ThemeCreateParentWindow(
833 if (pMonitorContext->nDpi != pTheme->nDpi)
834 {
835 ScaleTheme(pTheme, pMonitorContext->nDpi, pMonitorRect->left, pMonitorRect->top, dwStyle, NULL != hMenu, dwExStyle);
836 + fScaledTheme = TRUE;
837 }
838
839 x = pMonitorRect->left + (pMonitorRect->right - pMonitorRect->left - pTheme->nWindowWidth) / 2;
@@ -839,6 +847,12 @@ DAPI_(HRESULT) ThemeCreateParentWindow(
847 }
848 }
849
850 + // Make sure the client area matches the specified width and height.
851 + if (!fScaledTheme)
852 + {
853 + AdjustThemeWindowRect(pTheme, dwStyle, NULL != hMenu, dwExStyle);
854 + }
855 +
856 hWnd = ::CreateWindowExW(dwExStyle, szClassName, szWindowName, dwStyle, x, y, pTheme->nWindowWidth, pTheme->nWindowHeight, hwndParent, hMenu, hInstance, lpParam);
857 ThmExitOnNullWithLastError(hWnd, hr, "Failed to create theme parent window.");
858 ThmExitOnNull(pTheme->hwndParent, hr, E_INVALIDSTATE, "Theme parent window is not set, make sure ThemeDefWindowProc is called for WM_NCCREATE.");
@@ -6597,8 +6611,6 @@ static void ScaleTheme(
6611 __in DWORD dwExStyle
6612 )
6613 {
6600 - RECT rect = { };
6601 -
6614 pTheme->nDpi = nDpi;
6615
6616 pTheme->nHeight = DpiuScaleValue(pTheme->nDefaultDpiHeight, pTheme->nDpi);
@@ -6606,13 +6618,7 @@ static void ScaleTheme(
6618 pTheme->nMinimumHeight = DpiuScaleValue(pTheme->nDefaultDpiMinimumHeight, pTheme->nDpi);
6619 pTheme->nMinimumWidth = DpiuScaleValue(pTheme->nDefaultDpiMinimumWidth, pTheme->nDpi);
6620
6609 - rect.left = x;
6610 - rect.top = y;
6611 - rect.right = x + pTheme->nWidth;
6612 - rect.bottom = y + pTheme->nHeight;
6613 - DpiuAdjustWindowRect(&rect, dwStyle, fMenu, dwExStyle, pTheme->nDpi);
6614 - pTheme->nWindowWidth = rect.right - rect.left;
6615 - pTheme->nWindowHeight = rect.bottom - rect.top;
6621 + AdjustThemeWindowRect(pTheme, dwStyle, fMenu, dwExStyle);
6622
6623 ScaleControls(pTheme, pTheme->cControls, pTheme->rgControls, pTheme->nDpi);
6624
@@ -6622,6 +6628,24 @@ static void ScaleTheme(
6628 }
6629 }
6630
6631 +static void AdjustThemeWindowRect(
6632 + __in THEME* pTheme,
6633 + __in DWORD dwStyle,
6634 + __in BOOL fMenu,
6635 + __in DWORD dwExStyle
6636 + )
6637 +{
6638 + RECT rect = { };
6639 +
6640 + rect.left = 0;
6641 + rect.top = 0;
6642 + rect.right = pTheme->nWidth;
6643 + rect.bottom = pTheme->nHeight;
6644 + DpiuAdjustWindowRect(&rect, dwStyle, fMenu, dwExStyle, pTheme->nDpi);
6645 + pTheme->nWindowWidth = rect.right - rect.left;
6646 + pTheme->nWindowHeight = rect.bottom - rect.top;
6647 +}
6648 +
6649 static void ScaleControls(
6650 __in THEME* pTheme,
6651 __in DWORD cControls,