0
votes

I have a C++ / MFC app and I trying to save and restore the window placement of my CFrameWnd derived main frame. I have my GetWindowPlacement and SetWindowPlacement calls in the appropriate places, and all seems to be working well.

That is until I 'store' the window when it is maximised. In that case, when I re-open the app and use the debugger to step over my SetWindowPlacement call, I see that it is placed maximised, as I wanted.

But then if I continue execution, something else 'restores' my window to it's non-maximised size. How do I discover what is doing that? (Since I'm not calling ShowWindow anywhere else)

EDIT: It seems to stem from CFrameWnd::InitialUpdateFrame:

    int nCmdShow = -1;      // default
    CWinApp* pApp = AfxGetApp();
    if (pApp != NULL && pApp->m_pMainWnd == this)
    {
        nCmdShow = pApp->m_nCmdShow; // use the parameter from WinMain
        pApp->m_nCmdShow = -1; // set to default after first time
    }
    ActivateFrame(nCmdShow);

If I set my app m_nCmdShow to SW_MAXIMIZED on start up, it shows maxed - but it's always maxed! I have my SetWindowPlacement in my CMainFrame::OnActivate - should it be somewhere else?

1

1 Answers

-1
votes

So In my App start up I did this:

WINDOWPLACEMENT* lwp;
UINT nl;
if (AfxGetApp()->GetProfileBinary(_T("MainFrame"), _T("WP"), (LPBYTE*)&lwp, &nl))
{
    m_nCmdShow = lwp->showCmd;
}
delete [] lwp;

It seems to work