MFC Programming Hints


This contains hints on nagging things in MFC. I'll continue to add them as time goes on. If you know something that may help people, please email me.

Last updated Nov 29, 2000


Getting rid of "Untitled" on the title bar

If AppWizard created your MFC application, you will have "Untitled-classname" on your title bar. To change the "Untitled" go to your *Doc.cpp. There is a routine called "OnNewDocument". Before you call the CDocument::OnNewDocument put the line

SetTitle("My new title");

This will change the titlebar to "My new title - classname."

If you don't want the "Untitled -" at all, you need to do the following. Go to your MainFrame class and override the PreCreateWindow function. You need the following in it:

cs.style &= ~FWS_ADDTOTITLE ;

Don't forget, you need to call CFrameWnd::PreCreateWindow at the end of this function.


Discovering if a previous instance of your application is running

Previously, for Win3.1, an application could check it's hPrevInstance variable to see if the application is already running. That no longer works for Win95. A good way to do this now is to look for your window name.

FindWindow (window-name, NULL)

If that returns NULL, the program is not running. Otherwise, it will return the handle to the window of the other program.


Books

MFC books
BookCover Programming Windows With Mfc (Second Ed) by Jeff Prosise
Microsoft Press, 1999, ISBN#1-57-231695-0
Order from Amazon.com
Book Cover MFC Internals by George Shepherd
Addison-Wesley Pub Co, 1996, ISBN#1-201-40721-3
More information from the Authors
Order from Amazon.com

The MFC FAQ
MFC FAQ (web browsable)
If that doesn't work, try - MSDN MFC FAQ
Go to driver annotation page