开发者

Maximized Window Restores to Full Screen

开发者 https://www.devze.com 2023-01-15 00:31 出处:网络
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 si

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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消