How to get rid of "Untitled - MyApp" in MFC | CodeGuru

How to get rid of “Untitled – MyApp” in MFC

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 6, 1998
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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)
     {
       CDocument::SetTitle("MyTitle");
     }

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;
      csAppName.Format(AFX_IDS_APP_TITLE);

      // Set caption of main frame window
      //---------------------------------
      SetWindowText(csAppName);
    }

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);
}
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.