A scroll bar can be included in a window as either a standard scroll bar or as a scroll bar control. A standard scroll bar is part of the nonclient area of a window. It is created with the window and displayed when the window is displayed. The sole purpose of a standard scroll bar is to let the user generate scrolling requests for the window's client area. You can include a standard scroll bar in a window by specifying the WS_HSCROLL or WS_VSCROLL style, or both, when you create the window. The WS_HSCROLL style creates a horizontal scroll bar that is positioned at the bottom of the client area. The WS_VSCROLL style creates a vertical scroll bar that is positioned at the right of the client area. A standard horizontal scroll bar has the standard scroll bar height and width as defined by the SM_CXHSCROLL and SM_CYHSCROLL system metric values. The width and height of a standard vertical scroll bar are defined by the SM_CXVSCROLL and SM_CYVSCROLL values.
A scroll bar control is a control window that belongs to the SCROLLBAR window class. A scroll bar control looks and acts like a standard scroll bar, but a scroll bar control is a separate window, not part of any window. As a separate window, a scroll bar control can receive the input focus, and indicates this by displaying a flashing caret in the scroll box. A scroll bar control also has a built-in keyboard interface that lets the user direct scrolling—a standard scroll bar does not. You can use as many scroll bar controls as you need to in a single window. When you create a scroll bar control, you must specify the scroll bar's size and position. Also, if you use a scroll bar control in a window that can be resized, you must adjust the scroll bar's size whenever the size of the window changes.
The advantage of using a standard scroll bar is that Windows creates the scroll bar and sets its size and position automatically. However, standard scroll bars are sometimes too restrictive. For example, suppose you want to divide a client area into quadrants and use a separate set of scroll bars to control the contents of each quadrant. You can't use standard scroll bars because you can only create one set for a particular window. Instead, you should use scroll bar controls because a window can contain any number of them.
Scroll bar controls are often used for purposes other than scrolling the contents of a window. For example, the Mouse application in Control Panel uses scroll bar controls to make it possible for the user to set the mouse tracking speed and double-click speed. The following illustration shows the Mouse application's Double Click Speed scroll bar control:
A scroll bar control can have a number of styles that control the orientation and position of the scroll bar. You specify the styles when you call the CreateWindowEx function to create a scroll bar control. Some of the styles create a scroll bar control that has the default width or height. However, you must always specify the x- and y-coordinates and the other dimensions of the scroll bar. The following list shows the scroll bar control styles and provides a description of each style:
Style | Description |
SBS_BOTTOMALIGN | Positions a horizontal scroll bar at the bottom of the rectangle specified by the x, y, nWidth, and nHeight parameters of the CreateWindowEx function. The SBS_HORZ style must also be specified. The scroll bar has the default height for standard horizontal scroll bars. |
SBS_HORZ | Creates a horizontal scroll bar. If neither the SBS_BOTTOMALIGN nor SBS_TOPALIGN style is specified, the scroll bar has the height, width, and position given in the CreateWindowEx function. |
SBS_LEFTALIGN | Positions a vertical scroll bar at the left side of the rectangle specified by the x, y, nWidth, and nHeight parameters of the CreateWindowEx function. The SBS_VERT style must also be specified. The scroll bar has the default width for standard vertical scroll bars. |
SBS_RIGHTALIGN | Positions a vertical scroll bar at the right side of the rectangle specified by the x, y, nWidth, and nHeight parameters of the CreateWindowEx function. The SBS_VERT style must also be specified. The scroll bar has the default width for standard vertical scroll bars. |
SBS_TOPALIGN | Positions a horizontal scroll bar at the top of the rectangle specified by the x, y, nWidth, and nHeight parameters of the CreateWindowEx function. The SBS_HORZ style must also be specified. The scroll bar has the default height for standard horizontal scroll bars. |
SBS_VERT | Creates a vertical scroll bar. If neither the SBS_RIGHTALIGN nor SBS_LEFTALIGN style is specified, the scroll bar has the height, width, and position given in the CreateWindowEx function. |