45.1.4 Scroll Bar Requests

The user makes scrolling requests by clicking the various parts of a scroll bar. Windows sends the request to the given window in the form of a WM_HSCROLL or WM_VSCROLL message. A horizontal scroll bar sends the WM_HSCROLL message; a vertical scroll bar sends WM_VSCROLL message. Each message includes a scroll bar notification code corresponding to the user's action, the handle of the scroll bar (scroll bar controls only), and, in some cases, the position of the scroll-box.

The following illustration shows the notification codes generated by the using clicking on various parts of a scroll bar:

The scroll bar notification codes specify the action the user has taken. Your application should examine the notification codes that accompany the WM_HSCROLL and WM_VSCROLL messages and should perform the appropriate scrolling operation. The Windows user-interface guidelines recommend certain responses for each action. The following is a list of the notification codes. For each code, the user's action is specified, followed by the application's response. In each case, a “unit” is defined by your application and should be appropriate for the given data. For example, for scrolling text vertically, the typical unit is a line.

Notification code Description Action

SB_LINEUP Indicates that the user clicked the top scroll arrow. Decrement the scroll-box position by one, and scroll toward the top of the data by one unit.
SB_LINEDOWN Indicates that the user clicked the bottom scroll arrow. Increment the scroll-box position by one, and scroll toward the bottom of the data by one unit.
SB_LINELEFT Indicates that the user clicked the left scroll arrow. Decrement the scroll-box position by one, and scroll toward the left end of the data by one unit.
SB_LINERIGHT Indicates that the user clicked the right scroll arrow. Increment the scroll-box position by one, and scroll toward the right end of the data by one unit.
SB_PAGEUP Indicates that the user clicked the scroll bar shaft above the scroll box. Decrement the scroll-box position by the number of data units in the window, and scroll toward the top of the data by the same number of units.
SB_PAGEDOWN Indicates that the user clicked the scroll bar shaft below the scroll box. Increment the scroll-box position by the number of data units in the window, and scroll toward the bottom of the data by the same number of units.
SB_PAGELEFT Indicates that the user clicked the scroll bar shaft to the left of the scroll box. Decrement the scroll-box position by the number of data units in the window, and scroll toward the left end of the data by the same number of units.
SB_PAGERIGHT Indicates that the user clicked the scroll bar shaft to the right of the scroll box. Increment the scroll-box position by the number of data units in the window, and scroll toward the right end of the data by the same number of units.
SB_THUMBTRACK Indicates that the user is dragging the scroll box. Applications that draw data quickly can set the scroll box to the position given in the message and scroll the data by the same number of units the scroll box has moved. Applications that cannot draw data quickly should wait for the SB_THUMBPOSITION code before moving the scroll box and scrolling the data.
SB_THUMBPOSITION Indicates that the user released the scroll box after dragging it. Set the scroll box to the position given in the message, and scroll the data by the same number of units the scroll box has moved.
SB_ENDSCROLL Indicates that the user released the mouse after holding it on an arrow or in the scroll bar shaft. No response is necessary.

A scroll bar generates the SB_THUMBPOSITION and SB_THUMBTRACK notification codes when the user clicks and drags the scroll box. Your application should process either SB_THUMBTRACK or SB_THUMBPOSITION, but not both.

The SB_THUMBPOSITION notification code occurs when the user releases the mouse button after clicking the scroll box. An application that processes this code performs the scrolling operation after the user has dragged the scroll box to the desired position and released the mouse button.

SB_THUMBTRACK notification codes occur as the user drags the scroll box. By processing SB_THUMBTRACK messages, you can scroll the contents of a window as the user drags the scroll box. However, a scroll bar can generate many SB_THUMBTRACK notification codes in a short period, so your application should process these codes only if it can quickly repaint the contents of the window.