From 47b97a968bcc3ea6ad686b3e367f3bc72d8b0a14 Mon Sep 17 00:00:00 2001 From: Xavier Roche Date: Sun, 26 Jul 2026 12:08:55 +0200 Subject: [PATCH] Give the restored window a sensible default size The frame starts maximized, and on a first run nothing ever set its restored rectangle, so it kept the CW_USEDEFAULT one MFC created it with. Un-maximizing therefore dropped to a small window on any screen, large ones included, and the panel gained scrollbars it had no reason to need. Set the restored rectangle to three quarters of the work area, centred, before maximizing. It scales with the display instead of being a fixed guess, and it only applies when there is no saved placement to honour. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_019HXNEMWtyrkW7xoD8ewcR3 Signed-off-by: Xavier Roche --- WinHTTrack/MainFrm.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/WinHTTrack/MainFrm.cpp b/WinHTTrack/MainFrm.cpp index 2831104..cb4cf72 100644 --- a/WinHTTrack/MainFrm.cpp +++ b/WinHTTrack/MainFrm.cpp @@ -139,8 +139,24 @@ void CMainFrame::InitialShowWindow(UINT nCmdShow) WINDOWPLACEMENT wp; if (!ReadWindowPlacement(&wp)) { - ShowWindow(SW_SHOWMAXIMIZED); /* by default, maximized */ - //ShowWindow(nCmdShow); + /* Maximized, but give the restored size something as well: with no explicit + rcNormalPosition the frame keeps CW_USEDEFAULT, so the first un-maximize + drops to a small window however large the screen is. */ + CRect work; + if (!::SystemParametersInfo(SPI_GETWORKAREA, 0, &work, 0)) + work.SetRect(0, 0, ::GetSystemMetrics(SM_CXSCREEN), ::GetSystemMetrics(SM_CYSCREEN)); + CRect normal(0, 0, work.Width()*3/4, work.Height()*3/4); + normal.OffsetRect(work.left + (work.Width() - normal.Width())/2, + work.top + (work.Height() - normal.Height())/2); + + WINDOWPLACEMENT init; + init.length = sizeof(init); + init.flags = 0; + init.showCmd = SW_SHOWMAXIMIZED; /* by default, maximized */ + init.ptMinPosition = CPoint(-1, -1); + init.ptMaxPosition = CPoint(-1, -1); + init.rcNormalPosition = normal; + SetWindowPlacement(&init); return; } if (nCmdShow != SW_SHOWNORMAL)