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