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

Started by
5 comments, last by Drew_Benton 18 years, 7 months ago
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]
Advertisement
Did you try using SetWindowText()?
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

Thanks for your reply SiCrane,
ArchG
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.
Aha!

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

ArchG
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.
Quote:Original post by SiCrane
OnCreate() 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.

This topic is closed to new replies.

Advertisement