The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.



Loads the specified layout of MDI Tabbed Groups and the list of previously opened documents.

virtual BOOL LoadMDIState(
   LPCTSTR lpszProfileName 

[in] lpszProfileName

Specifies the profile name.

TRUE if the load succeeded; FALSE if the load failed or there is no data to load.

To load or save the state of MDI tabs and groups and the list of opened documents, do the following:

  • Call CMDIFrameWndEx::SaveMDIState when the main frame is being closed

  • Call CMDIFrameWndEx::LoadMDIState when the main frame is being created. The recommended place for this call is before the main frame is displayed for the first time. Add CWinAppEx::EnableLoadWindowPlacement (FALSE); before pMainFrame->LoadFrame (IDR_MAINFRAME);. Add CBCGPWorkspace::ReloadWindowPlacement (pMainFrame); after the call to LoadMDIState to display the main frame at the position that was stored in the registry.

  • Override GetDocumentName in the CMDIChildWndEx- derived class if your application displays documents that are not stored as files. The returned string will be saved in the registry as the document identifier. The base implementation of CMDIChildWndEx::GetDocumentName returns a value obtained from CDocument::GetPathName.

  • Override CMDIFrameWndEx::CreateDocumentWindow to correctly create documents when they are being loaded from the registry. The first parameter is the string that GetDocumentName returned.


The following example shows how LoadMDIState is used in the VisualStudioDemo Sample: MFC Visual Studio Application.

// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;

if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
	if (!pMainFrame->LoadMDIState(GetRegSectionPath()))
	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;


Header: afxMDIFrameWndEx.h