3

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.

Adi Shavit
  • 16,743
  • 5
  • 67
  • 137
  • Is the main window a dialog or SDI/MDI frame? – Aidan Ryan Sep 03 '10 at 03:16
  • I have the same problem. When restoring a window that was set to maximized by SetWindowPlacement the window is "restored" to the same maximized size. Mine is MFC MDI main window, with calls to SetWindowPlacement from OnCreate, and GetWindowPlacement from OnClose. – Dialecticus Feb 19 '11 at 20:00

2 Answers2

2

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.

Dialecticus
  • 16,400
  • 7
  • 43
  • 103
-1

All information are in the file with extension .RC. I never used a Maximize/Restore procedures though you should look for a 'DIALOGEX' for the same window. You can change it using any editor (notepad, ultraedit etc.)

Sunscreen
  • 3,452
  • 8
  • 34
  • 40