Status Bars
The status bar window neither accepts user input nor generates command messages. Its job is simply to display text in panes under program control. The status bar supports two types of text panes—message line panes and status indicator panes. To use the status bar for application-specific data, you must first disable the standard status bar that displays the menu prompt and keyboard status.
The Status Bar Definition
The static indicators array that the MFC Application Wizard generates in the


Figure 13-3: The status bar and the indicators array.
The CStatusBar::SetIndicators member function, called in the application's derived frame class, configures the status bar according to the contents of the indicators array.
The Message Line
A message line pane displays a string that the program supplies dynamically. To set the value of the message line, you must first get access to the status bar object and then you must call the CStatusBar::SetPaneText member function with a zero-based index parameter. Pane 0 is the leftmost pane, 1 is the next pane to the right, and so forth.The following code fragment is part of a view class member function. Note that you must navigate up to the application object and then back down to the main frame window.
CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
CStatusBar* pStatus = &pFrame->m_wndStatusBar;
pStatus->SetPaneText(0, "message line for first pane");
Normally, the length of a message line pane is exactly one-fourth the width of the display. If, however, the message line is the first (index 0) pane, it is a stretchy pane without a beveled border. Its minimum length is one-fourth the display width, and it expands if room is available in the status bar.
The Status Indicator
A status indicator pane is linked to a single resource-supplied string that is displayed or hidden by logic in an associated update command user interface message handler function. An indicator is identified by a string resource ID, and that same ID is used to route update command user interface messages. The Caps Lock indicator is handled in the frame class by a message map entry and a handler function equivalent to those shown below. The Enable function turns on the indicator if the Caps Lock mode is set.
ON_UPDATE_COMMAND_UI(ID_INDICATOR_CAPS, OnUpdateKeyCapsLock)
void CMainFrame::OnUpdateKeyCapsLock(CCmdUI* pCmdUI)
{
pCmdUI->Enable(::GetKeyState(VK_CAPITAL) & 1);
}
The status bar update command user interface functions are called during idle processing so that the status bar is updated whenever your application receives messages.The length of a status indicator pane is the exact length of the corresponding resource string.
Taking Control of the Status Bar
In the standard application framework implementation, the status bar has the child window ID AFX_IDW_STATUS_BAR. The application framework looks for this ID when it wants to display a menu prompt. The update command user interface handlers for the keyboard state indicators, embedded in the frame window base class, are linked to the following string IDs: ID_INDICATOR_CAPS, ID_INDICATOR_NUM, and ID_INDICATOR_SCRL. To take control of the status bar, you must use a different child window ID and different indicator ID constants.
The status bar window ID is assigned in the CStatusBar::Create function called by the derived frame class OnCreate member function. That function is contained in the

m_wndStatusBar.Create(this);
with this call
m_wndStatusBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM,
ID_MY_STATUS_BAR);
You must also, of course, define the ID_MY_STATUS_BAR constant in the
