Changing a MFC Frame Window Title

Click here to change the theme.

MFC frame window titles consist of a document name and an application name. The format "application name - document name" is used if the FWS_ADDTOTITLE frame window style is set (the default is for it to be set). The FWS_PREFIXTITLE frame window style causes the title to be reversed so that the document name is before the application name.

Document Name

If there is a need to change the document name dynamically during execution, then it can be changed using CDocument::SetTitle, which will call OnUpdateFrameTitle to effect the change for each view of the document.

Application Name

If you want the main window caption to consist only of the application name then remove the FWS_ADDTOTITLE frame window style by doing the following in an override of the PreCreateWindow() function in the MainFrame class: &= ~FWS_ADDTOTITLE;

If, after a project has been generated by the AppWizard, the application name needs to be modified permanently, then see Microsoft Knowledge Base article Q129095 - INFO: Format of the Document Template String for a description of how to modify the windowTitle string.

There is not, however, a way to change the application name for window titles as easily as for document names, but fortunately it is almost as easy. The application name is stored in the protected m_strTitle member variable of CFrameWnd. So to change it anytime after the window has been created, create a member function in your CFrameWnd or CMDIFrameWnd derived class, as in the following:

void CMainFrame::SetAppName(LPCTSTR Title) {
m_strTitle = Title;

Then to change the application name in the window title, you must first call SetAppName, but then it is necessary to call OnUpdateFrameTitle to ensure the change is applied. Assuming that SetAppName is a public member function, the application name in the main frame's window title can be changed from anywhere after it has been created. For example, something such as the following could be used to change it from the view:

CMainFrame *pFrame=(CMainFrame*)GetParent();
pFrame->SetAppName("New Application Name");

However for that to work, you must have the FWS_ADDTOTITLE frame window style set; that is the default, so normally that is not a problem.

If you need to modify a frame window's title in a more customized manner, then the documentation of how to do that is scattered and confusing. The OnUpdateFrameTitle function is likely included in the solution, so search for descriptions of overriding OnUpdateFrameTitle.