How to modify MFC window title

A virtual function SetTitle is defined in the document class of MFC program, which is used to set the first half of the window title. If you only want to modify the untitled part, you can overload the function of the document class. The second half of the window title can be set by SetWindowText, or you can edit the IDR_MAINFRAME string in the string resource to replace the string before the first/n. If you want to delete the "untitled" part, you must repair the style of the window.

First, modify the first half.

1) can overload the virtual function SetTitle of the document class.

void CT est Doc::settile(lpctstr lpsz title){ CDocument::settile(l " your title "); } You can also add settile (L "your title") in CTestDoc::OnNewDocument ();

Second, modify the second half.

1) Modify the resource string:

Modify the IDR_MAINFRAME in the resource file to

Modify/n/nchange/n/n/nchangetitle.document/nchangedocument here.

The meaning of each substring in the resource string can be referred to as the meaning of each substring in the IDR_MAINFRAME string resource.

2) Use the SetWindowText(L "Your Title") of the frame window class:

Call the following statement in the application class CTestApp::InitInstance ()

m _ pMainWnd-& gt; SetWindowText(L "your title");

Or use afxgetmainwnd ()-> elsewhere; SetWindowText(L "your title");

3) If you want to remove the "-"sign in the middle of the title, you can copy the OnUpdateFrameTitle function of the CFramWnd class, which cannot be found in the help file provided by VC and must be added manually.

Virtual void on updateframe (boolnada);

void CMainFrame::OnUpdateFrameTitle(BOOL NaDa){ CString cs appname;

csAppName。 Format (afx _ ids _ app _ title);

SetWindowText(cs appname); } The result displayed at this time is only the string defined by the string resource AFX_IDS_APP_TITLE.

4) Modify the window style in the PreCreateWindow function of CMainFrame:

Returns cframewnd:: precreatewindow (cs); } Using this method, the title of the window only displays the part before the first /n in the IDR_MAINFRAME string.