# Changing the Title Bar in MFC!?!? [RESOLVED]

This topic is 4874 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I was recently asked to write a small program. Since the program is rather small I thought I'd use MFC to write it. I've never used MFC before, but how hard could it be right?? Well after screwing around for like an hour, I still cannot find out how to change the Window Title Bar. I know this is probably something simple, but I can't find. I have tried changing the CREATESTRUCT cs structures WindowName member but that doesn't do anything...the title bar constantly sticks at "untitled - AppName" Any help on this issue would be appreciated. Thanks, ArchG [Edited by - ArchG on September 14, 2005 5:55:50 PM]

##### Share on other sites
Did you try using SetWindowText()?

##### Share on other sites
Yes,
this->SetWindowTextW(_T("blah blah"));

causes an assert failure...I'm not really sure why it did that, so I just assumed that was not the way to change the title bar text..I'll mess around with it some more I guess..
Is there another way to change it? Or where should I be calling that?

I did it in the PreCreateWindow function of the MainFrm.cpp

ArchG

##### Share on other sites
Whatever you named your project, let's say MFCTest, open up that cpp file. For exmaple, MFCTest.cpp. Scroll down to the InitInstance function. At the bottom of that function, simply add in m_pMainWnd->SetWindowText( "Your Caption Here" ); and you will have changed the title. They was using the function as SiCrane mentioned, but you need to call it from your main App class. I'm sure you could find other places to put it as well, but I just tried that and it worked fine for me.

##### Share on other sites
Aha!

Sorry for wasting your time with that ;-) Thanks, a bunch Drew

ArchG

##### Share on other sites
The problem is that internally, SetWindowText() causes a WM_SETTEXT message to be sent to the window. PreCreateWindow() is called before the window is created. You just need to put the call to SetWindowText() sometime after the window is created; it doesn't need to be called from the app class. OnCreate() should work as well.

##### Share on other sites
Quote:
 Original post by SiCraneOnCreate() should work as well.

Strangely enough, it does not work in MFC in VS7. I tried adding it in various posistions of the int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) function (the only OnCreate function by default) and it didn't work. I veen tried changing the lpCreateStruct's member of lpszName and same deal. I know when you use a Dialog based MFC app, you can add it to the BOOL Class::OnInitDialog() function, and that's where that goes. As for where else it can be changed, I can't seem to find anywhere.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634090
• Total Posts
3015432
×