From eeebfc6feddc39124f77c1252c65436ce5cc85e2 Mon Sep 17 00:00:00 2001 From: Marco Maroni <166719395+marcomaroni-github@users.noreply.github.com> Date: Fri, 17 Jul 2026 12:06:23 +0200 Subject: [PATCH] fix: restore calculator window on-screen when saved monitor is disconnected PlaceInitial() restored the saved window position from the registry without checking that it still landed on a connected monitor. After detaching an external display the window ended up off-screen and invisible (ToggleVisible shows it with SWP_NOMOVE). Validate the target rect with MonitorFromRect (MONITOR_DEFAULTTONULL); if it intersects no active monitor, discard the saved position and fall through to the first-run bottom-right anchoring. Co-Authored-By: Claude Opus 4.8 (1M context) --- CalculatorWindow.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/CalculatorWindow.cpp b/CalculatorWindow.cpp index 0edc207..e79d325 100644 --- a/CalculatorWindow.cpp +++ b/CalculatorWindow.cpp @@ -169,8 +169,15 @@ void CCalculatorWindow::PlaceInitial() AdjustWindowRectEx(&r, (DWORD)GetWindowLongPtr(GWL_STYLE), FALSE, (DWORD)GetWindowLongPtr(GWL_EXSTYLE)); - SetWindowPos(NULL, r.left, r.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER); - return; + // Only restore the saved position if it still lands on a connected + // monitor. Otherwise (e.g. the window was left on an external display + // that is no longer attached) the point is off-screen and the window + // would be invisible; fall through to first-run anchoring instead. + RECT full = { r.left, r.top, r.left + w, r.top + h }; + if (::MonitorFromRect(&full, MONITOR_DEFAULTTONULL) != NULL) { + SetWindowPos(NULL, r.left, r.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER); + return; + } } // First run: anchor bottom-right, just above the notification area. APPBARDATA abd{}; abd.cbSize = sizeof(abd); -- 2.51.2