aboutsummaryrefslogtreecommitdiff
path: root/src/dutil/thmutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/dutil/thmutil.cpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/dutil/thmutil.cpp b/src/dutil/thmutil.cpp
index 4da489e4..a1b101e8 100644
--- a/src/dutil/thmutil.cpp
+++ b/src/dutil/thmutil.cpp
@@ -603,10 +603,14 @@ DAPI_(HRESULT) ThemeCreateParentWindow(
603 __in_opt HWND hwndParent, 603 __in_opt HWND hwndParent,
604 __in_opt HINSTANCE hInstance, 604 __in_opt HINSTANCE hInstance,
605 __in_opt LPVOID lpParam, 605 __in_opt LPVOID lpParam,
606 __in THEME_WINDOW_INITIAL_POSITION initialPosition,
606 __out_opt HWND* phWnd 607 __out_opt HWND* phWnd
607 ) 608 )
608{ 609{
609 HRESULT hr = S_OK; 610 HRESULT hr = S_OK;
611 DPIU_MONITOR_CONTEXT* pMonitorContext = NULL;
612 POINT pt = { };
613 RECT* pMonitorRect = NULL;
610 HWND hWnd = NULL; 614 HWND hWnd = NULL;
611 615
612 if (pTheme->hwndParent) 616 if (pTheme->hwndParent)
@@ -614,6 +618,29 @@ DAPI_(HRESULT) ThemeCreateParentWindow(
614 ThmExitOnFailure(hr = E_INVALIDSTATE, "ThemeCreateParentWindow called after the theme was loaded."); 618 ThmExitOnFailure(hr = E_INVALIDSTATE, "ThemeCreateParentWindow called after the theme was loaded.");
615 } 619 }
616 620
621 if (THEME_WINDOW_INITIAL_POSITION_CENTER_MONITOR_FROM_COORDINATES == initialPosition)
622 {
623 pt.x = x;
624 pt.y = y;
625 hr = DpiuGetMonitorContextFromPoint(&pt, &pMonitorContext);
626 if (SUCCEEDED(hr))
627 {
628 pMonitorRect = &pMonitorContext->mi.rcWork;
629 if (pMonitorContext->nDpi != pTheme->nDpi)
630 {
631 ScaleTheme(pTheme, pMonitorContext->nDpi, pMonitorRect->left, pMonitorRect->top);
632 }
633
634 x = pMonitorRect->left + (pMonitorRect->right - pMonitorRect->left - pTheme->nWidth) / 2;
635 y = pMonitorRect->top + (pMonitorRect->bottom - pMonitorRect->top - pTheme->nHeight) / 2;
636 }
637 else
638 {
639 x = CW_USEDEFAULT;
640 y = CW_USEDEFAULT;
641 }
642 }
643
617 hWnd = ::CreateWindowExW(dwExStyle, szClassName, szWindowName, dwStyle, x, y, pTheme->nWidth, pTheme->nHeight, hwndParent, NULL, hInstance, lpParam); 644 hWnd = ::CreateWindowExW(dwExStyle, szClassName, szWindowName, dwStyle, x, y, pTheme->nWidth, pTheme->nHeight, hwndParent, NULL, hInstance, lpParam);
618 ThmExitOnNullWithLastError(hWnd, hr, "Failed to create theme parent window."); 645 ThmExitOnNullWithLastError(hWnd, hr, "Failed to create theme parent window.");
619 ThmExitOnNull(pTheme->hwndParent, hr, E_INVALIDSTATE, "Theme parent window is not set, make sure ThemeDefWindowProc is called for WM_NCCREATE."); 646 ThmExitOnNull(pTheme->hwndParent, hr, E_INVALIDSTATE, "Theme parent window is not set, make sure ThemeDefWindowProc is called for WM_NCCREATE.");
@@ -625,6 +652,8 @@ DAPI_(HRESULT) ThemeCreateParentWindow(
625 } 652 }
626 653
627LExit: 654LExit:
655 MemFree(pMonitorContext);
656
628 return hr; 657 return hr;
629} 658}
630 659
@@ -5471,7 +5500,10 @@ static void ScaleTheme(
5471 5500
5472 ScaleControls(pTheme, pTheme->cControls, pTheme->rgControls, pTheme->nDpi); 5501 ScaleControls(pTheme, pTheme->cControls, pTheme->rgControls, pTheme->nDpi);
5473 5502
5474 ::SetWindowPos(pTheme->hwndParent, NULL, x, y, pTheme->nWidth, pTheme->nHeight, SWP_NOACTIVATE | SWP_NOZORDER); 5503 if (pTheme->hwndParent)
5504 {
5505 ::SetWindowPos(pTheme->hwndParent, NULL, x, y, pTheme->nWidth, pTheme->nHeight, SWP_NOACTIVATE | SWP_NOZORDER);
5506 }
5475} 5507}
5476 5508
5477static void ScaleControls( 5509static void ScaleControls(