A status bar is a horizontal window at the bottom of a parent window in which an application can display various kinds of status information. The status bar can be divided into parts to display more than one type of information.
You can create a status bar by using the
The default position of a status bar is along the bottom of the parent
window, but you can specify the
You can specify the
The window procedure for the status bar automatically sets the initial size and position of the window, ignoring the values specified in the CreateWindowEx function. The width is the same as that of the parent window's client area. The height is based on the metrics of the font that is currently selected into the status bar's device context and on the width of the window's borders.
The window procedure automatically adjusts the size of the status bar
whenever it receives a
An application can set the minimum height of a status bar's drawing area by
sending the window an
You retrieve the widths of the borders of a status bar by sending the window
an
A status bar can have many different parts, each displaying a different line
of text. You divide a status bar into parts by sending the window an
A status bar can have a maximum of 256 parts, although applications typically
use far fewer than that. You retrieve a count of the parts in a status bar, as
well as the coordinate of the right edge of each part, by sending the window an
You set the text of any part of a status bar by sending the
By default, text is left-aligned within the specified part of a status bar. You can embed tab characters (\ t) in the text to center or right-align it. Text to the right of a single tab character is centered, and text to the right of a second tab character is right-aligned.
To retrieve text from a status bar, use the
If your application uses a status bar that has only one part, you can use the
To display a line of status without creating a status bar, use the
You can define individual parts of a status bar to be owner-drawn parts. Using this technique gives you more control than you would otherwise have over the appearance of the window part. For example, you can display a bitmap rather than text or draw text using a different font.
To define a window part as owner-drawn, send the SB_SETTEXT message to the status bar, specifying the part and the SBT_OWNERDRAW drawing technique. When SBT_OWNERDRAW is specified, the lParam parameter is a 32-bit application-defined value that the application can use when drawing the part. For example, you can specify a font handle, a bitmap handle, an address of a string, and so on.
When a status bar needs to draw an owner-drawn part, it sends the
| Member | Description |
|---|---|
| CtlType | Undefined; do not use. |
| CtlID | Child window identifier of the status bar. |
| itemID | Zero-based index of the part to be drawn. |
| itemAction | Undefined; do not use. |
| itemState | Undefined; do not use. |
| hwndItem | Handle to the status bar. |
| hDC | Handle to the device context of the status bar. |
| rcItem | Coordinates of the window part to be drawn. The coordinates are relative to the upper left corner of the status bar. |
| itemData | Application-defined 32-bit value specified in the lParam parameter of the SB_SETTEXT message. |
You put a status bar in "simple mode" by sending it an
The string that a status bar displays while in simple mode is maintained separately from the strings that it displays while in nonsimple mode. This means you can put the window in simple mode, set its text, and switch back to nonsimple mode without the nonsimple mode text being changed.
When setting the text of a simple mode status bar, you can specify any drawing technique except SBT_OWNERDRAW. A simple mode status bar does not support owner drawing.
This section describes the messages handled by the window procedure for the predefined STATUSCLASSNAME class.
| Message | Default processing |
|---|---|
| WM_CREATE | Initializes the status bar. |
| WM_DESTROY | Frees resources allocated for the status bar. |
| WM_GETFONT | Returns the handle to the current font with which the status bar draws its text. |
| WM_GETTEXT | Copies the text from the first part of a status bar to a buffer. It returns a 32-bit value that specifies the length, in characters, of the text and the technique used to draw the text. |
| WM_GETTEXTLENGTH | Returns a 32-bit value that specifies the length, in characters, of the text in the first part of a status bar and the technique used to draw the text. |
| WM_NCHITTEST | Returns the HTBOTTOMRIGHT value if the mouse cursor is in the sizing
grip, causing the system to display the sizing cursor. If the mouse
cursor is not in the sizing grip, the status bar passes this message to
the |
| WM_PAINT | Paints the invalid region of the status bar. If the wParam parameter is non-NULL, the control assumes that the value is an HDC and paints using that device context. |
| WM_SETFONT | Selects the font handle into the device context for the status bar. |
| WM_SETTEXT | Copies the specified text into the first part of a status bar, using the default drawing operation (specified as zero). It returns TRUE if successful, or FALSE otherwise. |
| WM_SIZE | Resizes the status bar based on the current width of the parent window's client area and the height of the current font of the status bar. |
The following example demonstrates how to create a status bar that has a sizing grip and divide the window into four equal parts based on the width of the parent window's client area.
Example
// DoCreateStatusBar - creates a status bar and divides it into
// the specified number of parts.
// Returns the handle to the status bar.
// hwndParent - parent window for the status bar.
// nStatusID - child window identifier.
// hinst - handle to the application instance.
// nParts - number of parts into which to divide the status bar.
HWND DoCreateStatusBar(HWND hwndParent, int nStatusID, HINSTANCE
hinst, int nParts)
{
HWND hwndStatus;
RECT rcClient;
HLOCAL hloc;
LPINT lpParts;
int i, nWidth;
// Ensure that the common control DLL is loaded.
InitCommonControls();
// Create the status bar.
hwndStatus = CreateWindowEx(
0, // no extended styles
STATUSCLASSNAME, // name of status bar class
(LPCTSTR) NULL, // no text when first created
SBARS_SIZEGRIP | // includes a sizing grip
WS_CHILD, // creates a child window
0, 0, 0, 0, // ignores size and position
hwndParent, // handle to parent window
(HMENU) nStatusID, // child window identifier
hinst, // handle to application instance
NULL); // no window creation data
// Get the coordinates of the parent window's client area.
GetClientRect(hwndParent, &rcClient);
// Allocate an array for holding the right edge coordinates.
hloc = LocalAlloc(LHND, sizeof(int) * nParts);
lpParts = LocalLock(hloc);
// Calculate the right edge coordinate for each part, and
// copy the coordinates to the array.
nWidth = rcClient.right / nParts;
for (i = 0; i < nParts; i++) {
lpParts[i] = nWidth;
nWidth += nWidth;
}
// Tell the status bar to create the window parts.
SendMessage(hwndStatus, SB_SETPARTS, (WPARAM) nParts, (LPARAM)
lpParts);
// Free the array, and return.
LocalUnlock(hloc);
LocalFree(hloc);
return hwndStatus;
}
Status bar controls in Microsoft® Internet Explorer support the following new features.
| Icon Support | Icons can now be displayed in a status bar. The |
|---|---|
| ToolTip Support | The status bar now supports ToolTips. To enable ToolTips, the
SBT_TOOLTIPS style must be set when the status bar is created. The |
| Enhanced Simple Mode Support | The |
| Background Color Support | The |