Professional User Interface Suite, Copyright FOSS Software Inc. Help Published with Permission.

In most cases it is user friendly to store the state of the application's GUI elements between launches. Add to the header of the CMainFrame class the WINDOWPLACEMENT m_dataFrameWP variable. To the CMainFrame's constructor, add the initialization code below:

::memset( &m_dataFrameWP, 0, sizeof(WINDOWPLACEMENT) );
m_dataFrameWP.length = sizeof(WINDOWPLACEMENT);
m_dataFrameWP.showCmd = SW_HIDE;

To restore the state of the main frame window, overload the CMainFrame::ActivateFrame() method with:

void CMainFrame::ActivateFrame(int nCmdShow) 
{
    if( m_dataFrameWP.showCmd != SW_HIDE )
    {
      SetWindowPlacement( &m_dataFrameWP );
      CMDIFrameWnd::ActivateFrame( m_dataFrameWP.showCmd );
      m_dataFrameWP.showCmd = SW_HIDE;
      return;
    }
    CMDIFrameWnd::ActivateFrame(nCmdShow);
}

The invoke of the CExtControlBar::ProfileBarStateSave() function in the the DestroyWindow() method of CMainFrame saves the state of all control bars.

CWinApp * pApp = ::AfxGetApp();
ASSERT( pApp != NULL );
ASSERT( pApp->m_pszRegistryKey != NULL );
ASSERT( pApp->m_pszRegistryKey[0] != _T('\0') );
ASSERT( pApp->m_pszProfileName != NULL );
ASSERT( pApp->m_pszProfileName[0] != _T('\0') );
VERIFY(
    CExtControlBar::ProfileBarStateSave(
      this,
      pApp->m_pszRegistryKey,
      pApp->m_pszProfileName,
      pApp->m_pszProfileName
      )
    );

To load the application's saved state when starting the application, add the call of CExtControlBar::ProfileBarStateLoad() to the OnCreate() method:

if(!CExtControlBar::ProfileBarStateLoad(
    this,
    pApp->m_pszRegistryKey,
    pApp->m_pszProfileName,
    pApp->m_pszProfileName,
    &m_dataFrameWP
    )
)
{
    // if the state is not loaded, dock the initial layout
    // .............. 
}