Have you ever tried adding a pane in your frame window's status bar? It isn't hard, but there are a few tricks that can help you -- especially if you are trying to make it update continually (like a clock, for example).
The first step is to add an entry into the string table (in your resources). Make the entry look roughly like what will go in the status bar. For a clock you might put XX:XX:XX and name the string ID_INDICATOR_TIME. The exact characters don't really matter. Next, open your main frame's source file. You will find an array there called indicators. Here you add an entry for ID_INDICATOR_TIME or whatever you named your string.
If you run your program now, you'll see XX:XX:XX in the status bar. Not exactly what you had in mind. To change the text, you need a special message map handler for UPDATE_COMMAND_UI. Usually, you use Class Wizard to add this type of handler, but Class Wizard doesn't know about ID_INDICATOR_TIME. No problem. Open Class Wizard and select some menu item you aren't using in the class of interest (I used ID_APP_EXIT in the application class). Ask Class Wizard to set up a handler for UPDATE_COMMAND_UI for the menu item. When the Wizard suggests a name, override it with something more appropriate (OnUpdateTime, perhaps). Then edit the source file. Find the entry in the message map that reads:
ON_UPDATE_COMMAND_UI(ID_APP_EXIT,OnUpdateTime)
Change the ID_APP_EXIT to ID_INDICATOR_TIME and you are all set
MFC propagates update command UI messages just like command messages, so you can put the handler in any CCmdTarget-derived class. MFC sends the message during idle processing. However, as an optimization, MFC doesn't update anything after the first idle period. In other words, MFC updates only once each time there is some spare time after message processing. For most things, this is a good idea. After all, usually the state of the program can't change unless some sort of message has been processed. However, for a clock, it can change. Try this code in the handler:
void CStattimeApp::OnUpdateTime(CCmdUI* pCmdUI)
{
pCmdUI->SetText(CTime::GetCurrentTime().Format("%H:%M:%S"));
pCmdUI->Enable();
}
If you compile your program and run it, you'll see that the time only updates when a message passes (for example, when you move the mouse, or press a key). Any other time the clock is frozen.
What's the answer? You need to like to MFC and tell it that each idle message it gets is a new one. To do this, you can use Class Wizard to override the OnIdle function in the application object:
BOOL CStattimeApp::OnIdle(LONG lCount)
{
// fool base class into thinking it is always time to update
CWinApp::OnIdle(0);
return TRUE; // make sure we keep getting messages
}
Is this wasteful? Yes, since usually idle messages occur many times a second. However, you can pass idle messages less frequently. Suppose you wanted to update on every 10th idle message:
BOOL CStattimeApp::OnIdle(LONG lCount)
{
// fool base class into thinking it is always time to update
CWinApp::OnIdle(lCount%10);
return TRUE; // make sure we keep getting messages
}
This doesn't seem to affect the clock (at least, on a fast machine) and doesn't cause all the updating processing to occur on every idle call.