A scroll bar sends notification messages to its owner whenever the user clicks the scroll bar. WM_VSCROLL and WM_HSCROLL are the notification messages for vertical and horizontal scroll bars, respectively. If the scroll bar is a frame control window, the frame window passes the message to its client window.
Each notification message includes the scroll-bar identifier, scroll-bar command code corresponding to the action of the user, and, in some cases, the position of the slider. If an application creates a scroll bar as part of a frame control window, the scroll-bar identifier is the predefined constant FID_VERTSCROLL or FID_HORZSCROLL. Otherwise, it is the identifier given in the WinCreateWindow function.
The scroll-bar command codes specify the action the user has taken. Operating system user-interface guidelines recommend certain responses for each action.
Following is a list of the command codes; for each code, the user action is specified, followed by the application's response. In each case, a scrolling unit, appropriate for the given data, must be defined by the application. For example, for scrolling text vertically, the typical unit is a line.
┌────────────────────┬────────────────────────────────────────┐ │Command Code │Description │ ├────────────────────┼────────────────────────────────────────┤ │SB_LINEUP │Indicates that the user clicked the top │ │ │scroll arrow. Decrement the slider │ │ │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 │ │ │slider 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 slider │ │ │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 slider│ │ │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 background above the slider. │ │ │Decrement the slider 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 background below the slider. │ │ │Increment the slider 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 background to the left of the│ │ │slider. Decrement the slider 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 background to the right of │ │ │the slider. Increment the slider │ │ │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_SLIDERTRACK │Indicates that the user is dragging the │ │ │slider. Applications that draw data │ │ │quickly can set the slider to the │ │ │position given in the message, and │ │ │scroll the data by the same number of │ │ │units the slider has moved. Applications│ │ │that cannot draw data quickly should │ │ │wait for the SB_SLIDERPOSITION code │ │ │before moving the slider and scrolling │ │ │the data. │ ├────────────────────┼────────────────────────────────────────┤ │SB_SLIDERPOSITION │Indicates that the user released the │ │ │slider after dragging it. Set the slider│ │ │to the position given in the message, │ │ │and scroll the data by the same number │ │ │of units the slider was moved. │ ├────────────────────┼────────────────────────────────────────┤ │SB_ENDSCROLL │Indicates that the user released the │ │ │mouse after holding it on an arrow or in│ │ │the scroll-bar background. No response │ │ │is necessary. │ └────────────────────┴────────────────────────────────────────┘If the command code is SB_SLIDERTRACK or SB_SLIDERPOSITION, indicating that the user is moving the scroll-bar slider, the notification message also contains the current position of the slider.
The owner window can send a message to the scroll bar to read or reset the current value and range of the scroll bar. To reflect any changes in the state of the scroll bar, the owner window also can adjust the data the scroll bar controls.
An application can use the WinEnableWindow function to disable a scroll bar. A disabled scroll bar ignores the actions of the user, sending out no notification messages when the user tries to manipulate it. If an application has no data to scroll, or if all data fits in the client window, the application should disable the scroll bar.