Skip to content

Commit b924e5c

Browse files
vadzjanwilmans
authored andcommitted
Restore window geometry correctly, even in high DPI
The coordinates returned by GetWindowPlacement() must be passed to SetWindowPlacement() and not SetWindowPos() as the former functions account correctly for non-standard DPI, while the latter one does not. Using SetWindowPlacement() also allows to remove the checks for the coordinates being valid because the function already checks for this and will always position the window inside the visible area anyhow. Fixes #370.
1 parent fd80e5c commit b924e5c

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

application/DebugViewpp/MainFrame.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -682,12 +682,22 @@ bool CMainFrame::LoadSettings()
682682
DWORD cy = 0;
683683
CRegKey reg;
684684
reg.Create(HKEY_CURRENT_USER, RegistryPath);
685-
if (reg.QueryDWORDValue(L"X", x) == ERROR_SUCCESS && static_cast<int>(x) >= GetSystemMetrics(SM_XVIRTUALSCREEN) &&
686-
reg.QueryDWORDValue(L"Y", y) == ERROR_SUCCESS && static_cast<int>(y) >= GetSystemMetrics(SM_YVIRTUALSCREEN) &&
687-
reg.QueryDWORDValue(L"Width", cx) == ERROR_SUCCESS && static_cast<int>(x + cx) <= GetSystemMetrics(SM_XVIRTUALSCREEN) + GetSystemMetrics(SM_CXVIRTUALSCREEN) &&
688-
reg.QueryDWORDValue(L"Height", cy) == ERROR_SUCCESS && static_cast<int>(y + cy) <= GetSystemMetrics(SM_YVIRTUALSCREEN) + GetSystemMetrics(SM_CYVIRTUALSCREEN))
689-
{
690-
SetWindowPos(nullptr, x, y, cx, cy, SWP_NOZORDER);
685+
if (reg.QueryDWORDValue(L"X", x) == ERROR_SUCCESS &&
686+
reg.QueryDWORDValue(L"Y", y) == ERROR_SUCCESS &&
687+
reg.QueryDWORDValue(L"Width", cx) == ERROR_SUCCESS &&
688+
reg.QueryDWORDValue(L"Height", cy) == ERROR_SUCCESS)
689+
{
690+
WINDOWPLACEMENT placement = {0};
691+
placement.length = sizeof(placement);
692+
693+
placement.rcNormalPosition.left = x;
694+
placement.rcNormalPosition.top = y;
695+
placement.rcNormalPosition.right = x + cx;
696+
placement.rcNormalPosition.bottom = y + cy;
697+
698+
// Ignore errors, the worst that can happen is that the window doesn't
699+
// appear at the correct position, but this is not the end of the world.
700+
::SetWindowPlacement(*this, &placement);
691701
}
692702

693703
m_linkViews = Win32::RegGetDWORDValue(reg, L"LinkViews", 0) != 0;

0 commit comments

Comments
 (0)