3

I have an MFC document application where I want to remove the "Untitled - " from the caption.

It way my understanding that I need to remove the 'AddToTitle' property from the window style, and then I can set the title, and the'untitled' string would not be added.

I tried the following, but it does not work.

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
 ...

    lpCreateStruct->cx &= ~FWS_ADDTOTITLE;
    this->SetTitle(L"The New Title");
}

Anyone know how to remove 'Untitled' from the main window title?

Thanks,
-Matt

xMRi
  • 14,982
  • 3
  • 26
  • 59
netcat
  • 1,281
  • 1
  • 11
  • 21

4 Answers4

2

OnCreate is simply too late. You have to modify the style before the window is created. Just remove FWS_ADDTOTITLE in PreCreateWindow.

This is fairly well documented here.

IInspectable
  • 46,945
  • 8
  • 85
  • 181
xMRi
  • 14,982
  • 3
  • 26
  • 59
1

From my own answer on https://stackoverflow.com/a/35495606/383779

I had a similar problem in the past. The cause of main window's title text changing back is the function CFrameWndEx::OnUpdateFrameTitle. As it is virtual, you can override it on your own derived class to have the behaviour you want. It is a solution that worked for me.

Community
  • 1
  • 1
sergiol
  • 4,122
  • 4
  • 47
  • 81
1

I'm not sure if this is too late but you have a typo in your question

lpCreateStruct->cx &= ~FWS_ADDTOTITLE;

That should be

lpCreateStruct->style &= ~FWS_ADDTOTITLE;

And you need to add it in the PreCreateWindow function not the OnCreate function.

Runner
  • 11
  • 1
0
BOOL CMainFrame::PreCreateWindow( CREATESTRUCT& cs )
{
    if( !CFrameWnd::PreCreateWindow( cs ) )
        return FALSE;

    // Eliminate the ability to programmatically change the window title.
    cs.style &= ~( FWS_ADDTOTITLE );

    // Set the window title here!
    this->SetTitle( "Your custom window title goes here!" );

    return TRUE;
}
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 30 '22 at 03:47