Virtual Developer Workshop: Containerized Development with Docker

Microsoft outdid themselves when they designed MFC such that applications are automatically named according to the document view paradigm. When you use MFC to create either an SDI or MDI application, your main window is probably called something like "Untitled - MyApp." If you don't particularly care for the document view paradigm, other than perhaps wishing to benefit from the separation of user interface and program core, then you're left in the dark...

To get rid of the "Untitled" alone, you can override the CDocument virtual function "SetTitle" as shown below.

   void CMyDoc::SetTitle(LPCTSTR lpszTitle) 

This will produce a main window title of the type "MyTitle - MyApp". But perhaps all you want is "MyApp".

You can set the main window title from just about anywhere in your application using the statement shown below.
   (AfxGetMainWnd( ))->SetWindowText("MyApp");

The problem with this approach is that MFC in its infinite wisdom will reset your window title to the "Document - App" default as soon as a document object is constructed. If you care to change MFC's default behavior ( not advised ) look up WINMDI.CPP; it's the culprit.

Finally, you can overwrite the CFrameWnd virtual function "OnUpdateFrameTitle" in your apps CMainFrame class. Bud Milwood, a friend of mine, pointed out the function's very existence when I was loosing my sanity browsing the MFC online help. Don't try to look up "OnUpdateFrameTitle" in the Microsoft Developer Studio online help. It's not there. So use it merrily, but use it wisely, subsequent versions of MFC may not support it. The following code snippet shows how...

   void CMainFrame::OnUpdateFrameTitle(BOOL Nada) 
      // get app name from string table resource
      CString csAppName;

      // Set caption of main frame window

Another and probably safer method has been brought to my attention by Stephen Michael Schimpf at CyberSky.Simplenet.Com. You can modify the window style in 'PreCreateWindow' as follows:

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
    cs.style &= ~(LONG) FWS_ADDTOTITLE;
    return CFrameWnd::PreCreateWindow(cs);


  • CFrameTitle can also benefit from OnUpdateFrameTitle()

    Posted by Legacy on 11/11/2003 08:00am

    Originally posted by: Shaul

    If you want to embed a frame inside one of your panes, you can control its title text as follows:

    void CCmaTreeView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)

    CString title;

    title = "blabala";

    // Inform Frame
    CRightFrameWnd * frame = (CRightFrameWnd *)(GetParent())->GetParent();
    frame->OnUpdateFrameTitle(false); // false if you want your text only.

    *pResult = 0;

  • No need to override SetTitle

    Posted by Legacy on 05/31/2003 07:00am

    Originally posted by: Sam Hobbs

    I am nearly certain that it is not necessary to override CDocument::SetTitle; I am nearly certain that merely calling it will work.

  • Simpler way to change the default title

    Posted by Legacy on 01/03/2003 08:00am

    Originally posted by: Tony dixon

    there are two way to change the default title of a MFC app.

    1) in the appwizared on step 6 there is a Advanced button, press this and dialog will let you enter the name of the application.
    2) edit the string table for value (128 for SDI and 129 for MDI)this a list of items delimited by char (10), the first in the list is the app name.

    But this only works on MDI apps, for SDI the AppWizard has an error so you have to edit the IDR_MAINFRAME item in the string table.

    This is the string linked to the IDR_MAINFRAME item in the string table.

    Tonys Test App\n\nTest\nTonys Test Files (*.bin)\n.bin\nTest.Document\nTest Document

    The error is in the placement of the \n as so "Tonys Test App\n\n" the two \n is the error they should not be together, but one should be at the start of the string as below.

    \nTonys Test App\nTest\nTonys Test Files (*.bin)\n.bin\nTest.Document\nTest Document

    This works with out hard coding the name also windows use this value from the application when associating files.

  • Multiple view problem

    Posted by Legacy on 05/02/2002 07:00am

    Originally posted by: Jonathan Liu

    How to set different title names for multiple views of the same document. It seems the OnPaint() in view window is the place to set the title, although is not a nice way to do so.

  • Try this one, you can customize your title..

    Posted by Legacy on 05/31/2001 07:00am

    Originally posted by: Jacob Joseph

    Override CDocument::SetTitle, dont call the base class function. This will remove the 'Untitled' from a new document and also can customize your title. This eg sets the title as 'My App - doc name'. I did this for a SDI app.
    Dont forget to add the line

    cs.style &= ~(LONG) FWS_ADDTOTITLE; in
    CMainFrame :: PreCreateWindow(CREATESTRUCT& cs).

    void CGenericDoc::SetTitle(LPCTSTR lpszTitle)
    CWnd * pWnd = AfxGetMainWnd();
    CString csTitle;

    if ( CString(lpszTitle) == CString(_T("Untitled")) )
    if (pWnd)
    csTitle = csTitle + _T(" - ") + lpszTitle;
    if (pWnd)

  • Thanks all, especialy Richard.

    Posted by Legacy on 03/30/2000 08:00am

    Originally posted by: Dave Swann

    I'm a bit of a beginer trying to build a complex application.
    Iv'e discovered thay it is possible to have a FRAME window in a static splitter pane, and wanted to use its title bar to display info from the view. -
    void CSomeView::OnPaint()
    CPaintDC dc(this); // device context for painting
    CSomeFrame* pFrame;
    VERIFY( pFrame = (CSomeFrame*)GetParentFrame() );
    pFrame->SetWindowText("What ever the info is");

    Thanks again Richard.

  • More easy way

    Posted by Legacy on 02/02/2000 08:00am

    Originally posted by: Konstantin Pilkevitch

    I think that the best way to do this is to add such string
    in PreCreateWindow(CREATESTRUCT &cs) function of CMainFrame

    cs.style &= ~FWS_ADDTOTITLE;

  • Easier way

    Posted by Legacy on 08/14/1999 07:00am

    Originally posted by: Richard Stringer

    The easiest solution I have found is to override the OnPaint() function of the view class and using a pointer to the current frame window change the title using SetWindowText(). A advantage is thet you can easily change the title to relflect the current state of the application this way.

    void CMainView::OnPaint()
    CPaintDC dc(this); // device context for painting
    CMainFrame* pFrame;
    VERIFY( pFrame = (CMainFrame*)GetParentFrame() );
    pFrame->SetWindowText("What ever the title is");



  • But What If...

    Posted by Legacy on 05/12/1999 07:00am

    Originally posted by: Joe Cosentino

    But what if I wanted my title to say "MyApp - My Document"?
    How would I do that? Also, you don't need the line

    return CFrameWnd::PreCreateWindow(cs);

    in the last example. The line above it does all the work.

    --- Joseph Cosentino

  • Modify String Table

    Posted by Legacy on 12/17/1998 08:00am

    Originally posted by: Xiaolong Wu

    To change "MyApp" title to "New Title", one may open the String Table in the resource
    view and change the second word of the first string form "MyApp" to "New Title".

    Xiaolong Wu

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date