Creating a Simple-Mode Status Bar

A simple-mode status bar, such as the one shown in Figure 1-2, is useful for displaying a one-line description of a menu item as the user highlights the item or for displaying diagnostic information. To create a simple-mode status bar from a multiple-part status bar, you must send an SB_SIMPLE message to the status bar (or use the MFC SetSimple member function). But bear in mind that simple-mode status bars do not support owner drawing—so no cute bitmaps in this case.

Figure 1-2.

A status bar in simple mode.

The string that a status bar displays in simple mode is maintained separately from the strings it displays when it is in multiple-part mode. Thus, as you can see in the STATUS sample, you can put the window in simple mode, set its text, and switch back to multiple-part mode without having to reset the text. The following code demonstrates how to set the status bar mode in response to a command sent through the Options menu. When you set the text in the status bar, you should set wParam to 255, which signals that this is a simple-mode status bar and that the string should be maintained separately from the strings originally used in the multiple-part status bar.

case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDM_SIMPLE:
// Set the status bar to simple mode.
SendMessage (hWndStatus, SB_SIMPLE, (WPARAM)TRUE, 0L);
// Set the text of the status bar.
SendMessage (hWndStatus, SB_SETTEXT, 255,
(LPARAM)"We are now in simple mode.");
// Check the Simple menu option.
CheckMenuItem (GetMenu (hWnd), IDM_SIMPLE,
MF_CHECKED | MF_BYCOMMAND);
// Uncheck the Multiple menu option.
CheckMenuItem (GetMenu (hWnd), IDM_MULTIPLE,
MF_UNCHECKED | MF_BYCOMMAND);
break;

case IDM_MULTIPLE:
// Reset the status bar to multiple-part mode.
SendMessage (hWndStatus, SB_SIMPLE, (WPARAM)FALSE, 0L);
// Uncheck the Simple menu option.
CheckMenuItem (GetMenu (hWnd), IDM_SIMPLE,
MF_UNCHECKED | MF_BYCOMMAND);
// Check the Multiple menu option.
CheckMenuItem (GetMenu (hWnd), IDM_MULTIPLE,
MF_CHECKED | MF_BYCOMMAND);
break;

These operations are very similar in the MFC version of the sample. In that version, however, the SetSimple member function assumes TRUE by default, so I did not pass any parameters when I set my status bar to simple mode. When I reset the status bar to be multiple-part, I simply passed FALSE as the parameter.