It looks like you have used the code from the CodeProject article
Saving a windows size position and state in MFC[
^] but did not read it completely.
OnShowWindow
might be also called during program execution but you probably want it to be called only at program start. The article mentions that and provides code using the state variable
bOnce
to set the placement only when
OnShowWindow
is called the first time.
[EDIT: A different approach that I have used in the past]
Save the placement in
CMainFrame::OnClose
instead of
OnDestroy
.
Set the placement in
CMainFrame::OnCreate
instead of
OnShowWindow
. However, this will set only the position and the size will be set later when calling
ShowWindow
from
InitInstance
requiring that the command is passed stored:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
WINDOWPLACEMENT *lwp;
UINT nl;
if (AfxGetApp()->GetProfileBinary(_T("MainFrame"), _T("WP"), (LPBYTE*)&lwp, &nl))
{
m_nCmdShow = lwp->showCmd;
lwp->showCmd = SW_SHOWNORMAL;
SetWindowPlacement(lwp);
delete[] lwp;
}
}
void CMainFrame::ShowWindowInitial()
{
ShowWindow(m_nCmdShow);
UpdateWindow();
}
BOOL CMyApp::InitInstance()
{
pMainFrame->ShowWindowInitial();
}
[/EDIT]