Maximized Window Restores to Full Screen

3k views Asked by At

Using CWnd::ShowWindow(SW_SHOWMAXIMIZED) maximizes my app window as expected.

However, when clicking the restore button on the app (or double clicking the title-bar), the restored size is the same size as the maximized window, which is confusing for the user.

Using this alternative code has the same problem:

WINDOWPLACEMENT wndpl;
GetWindowPlacement(&wndpl);
wndpl.showCmd = SW_SHOWMAXIMIZED;
SetWindowPlacement(&wndpl);

How can I keep the default un-maximized size when restoring.

1

There are 1 answers

1
Dialecticus On

I've solved my problem, and the solution might solve yours too. My problem was that even though I called SetWindowPlacement(&wndpl) within CMainFrame::OnCreate the window was not properly restored if it was maximized. I added two lines of code before SetWindowPlacement, and now it works as expected.

CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    ...
    // Obtain wndpl, maybe from registry
    AfxGetApp()->m_nCmdShow = wndpl.showCmd;
    wndpl.showCmd = SW_SHOW;
    SetWindowPlacement(&wndpl);
}

These two lines helps underlying code not to mess things up when calling ActivateFrame, which calls ShowWindow with parameter obtained from CWinApp::m_nCmdShow.