Status Bar

There are two different types of elements in a status bar: Indicators and Separators.

Indicators are small elements that usually display a word or a short phrase. Examples of common indicators are ones for Cap Lock, Num Lock, and Insert. Most indicators are enabled when a particular key has been pressed. Open a document in Wordpad and press the Caps Lock key: the CAP indicator will appear in the status bar.

Separators are larger elements that display a longer phrase. The default status bar has a pane that displays a short phrase explaining the menu option or toolbar icon that is currently below the cursor.

Usually the Indicators have static content and the Separators have dynamic content. However, it is possible to make an Indicator dynamic, it just requires a little more coding. The main difference bewteen an Indicator and a Separator is that the Indicator has a default value corresponding to the string in the string table and has an automatic Update Command interface. A Separator does not have a default value and the programmer must take charge of updating the Separator.

Indicator Array

The status bar is defined by the indicator array. This is a global array that is defined in the CMainFrame class. The array can contain any number of Indicators and Separators. To add an indicator to the array, add the Indicator's ID from the String Table. All Separators have an ID of ID_SEPARATOR. Everything else should be the ID of an Indicator. This example has two Separators and one Indicator. The first Separator will expand to fill the status bar. The Indicator will be large enough to display the entire string from the String Table. All other Separtors will have a default width of 25% of the status bar.

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_LEFT,
	ID_SEPARATOR
};

Creating an Indicator

Add a new string to the String Table.

Updating an Indiactor

Determine which class will map the Update Command handler for the indicator.

The width of the indicator in the status bar will be set to the width of the string in the string table. When the UI is enabled, the string from the string table will appear in the status bar. When the UI is disabled, the indicator will be empty.

Creating a Separator

There can be more than one Separator. To create a Separator, just add an ID_SEPARATOR to the indicator array.

Updating a Separator

Determine when the Separator should be updated.

This example sets the text in OnLButtonDown and clears it in OnLButtonUp. This is being handled by the view, so the .cpp of the view should

#include "MainFrm.h"
void CStatusView::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
	pFrame->m_wndStatusBar.SetPaneText(2,"Left Button Down");
}

void CStatusView::OnLButtonUp(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
	pFrame->m_wndStatusBar.SetPaneText(2,"");
}

Modifying the Status Bar Info

Indicators have a default width that is the width of its default string. Separators either expand to fill the status bar, or have a default width of 25% of the status bar. These can be changed with a call to SetPaneInfo. The info is referenced by the index in the indicator array. The info that can be changed is

For example, this call would set the first pane to a width of 200 pixels, and it would not stretch to fill the status bar.

m_wndStatusBar.SetPaneInfo(0, ID_SEPARATOR, SBPS_NORMAL, 200);