1 out of 3 rated this helpful - Rate this topic

WM_HSCROLL message

Applies to: desktop apps only

The WM_HSCROLL message is sent to a window when a scroll event occurs in the window's standard horizontal scroll bar. This message is also sent to the owner of a horizontal scroll bar control when a scroll event occurs in the control.

A window receives this message through its WindowProc function.

WM_HSCROLL

    WPARAM wParam
    LPARAM lParam; 

Parameters

wParam

The HIWORD specifies the current position of the scroll box if the LOWORD is SB_THUMBPOSITION or SB_THUMBTRACK; otherwise, this word is not used.

The LOWORD specifies a scroll bar value that indicates the user's scrolling request. This word can be one of the following values.

ValueMeaning
SB_ENDSCROLL

Ends scroll.

SB_LEFT

Scrolls to the upper left.

SB_RIGHT

Scrolls to the lower right.

SB_LINELEFT

Scrolls left by one unit.

SB_LINERIGHT

Scrolls right by one unit.

SB_PAGELEFT

Scrolls left by the width of the window.

SB_PAGERIGHT

Scrolls right by the width of the window.

SB_THUMBPOSITION

The user has dragged the scroll box (thumb) and released the mouse button. The HIWORD indicates the position of the scroll box at the end of the drag operation.

SB_THUMBTRACK

The user is dragging the scroll box. This message is sent repeatedly until the user releases the mouse button. The HIWORD indicates the position that the scroll box has been dragged to.

 

lParam

If the message is sent by a scroll bar, then this parameter is the handle to the scroll bar control. If the message is not sent by a scroll bar, this parameter is NULL.

Return value

If an application processes this message, it should return zero.

Remarks

The SB_THUMBTRACK request code is typically used by applications that provide feedback as the user drags the scroll box.

If an application scrolls the content of the window, it must also reset the position of the scroll box by using the SetScrollPos function.

Note that the WM_HSCROLL message carries only 16 bits of scroll box position data. Thus, applications that rely solely on WM_HSCROLL (and WM_VSCROLL) for scroll position data have a practical maximum position value of 65,535.

However, because the SetScrollInfo, SetScrollPos, SetScrollRange, GetScrollInfo, GetScrollPos, and GetScrollRange functions support 32-bit scroll bar position data, there is a way to circumvent the 16-bit barrier of the WM_HSCROLL and WM_VSCROLL messages. See GetScrollInfo for a description of the technique.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

See also

Reference
GetScrollInfo
GetScrollPos
GetScrollRange
SetScrollInfo
SetScrollPos
SetScrollRange
WM_HSCROLL (trackbar)
WM_VSCROLL

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Trackbar controls
lParam

If the message is sent by a scroll bar, then this parameter is the handle to the scroll bar control. If the message is not sent by a scroll bar, this parameter is NULL.

-------------------------------------------------------------------------------
WRONG, in case of a scroll event sent by a trackbar control, lParam holds the handle of that control.

Example :

if((HWND)lParam == GetDlgItem(hWnd, ID_TRACKBAR)){
// your code here
}             

This works!
           
Liestviews - something special
Listviews ignore WM_HSCROLL completely.
Use LVM_SCROLL intstead !
LOWORD(wParam) is slightly different for Trackbar controls
When scrolling a Trackbar control, LOWORD(wParam) should be compared against a different set of constants.  See:
http://msdn.microsoft.com/en-us/library/bb760149%28v=VS.85%29.aspx#tkb_notifications
 
(Thankfully they're different in name only; the numerical values are the same.)
The values for the low order word of wParam are missing
The low-order word specifies a scroll bar value that indicates the user's scrolling request. This word can be one of the following values.

There are no values listed below that line of text.
Value
WM_HSCROLL = &H114
Public Enum WM_HSCROLL_low As Short
SB_ENDSCROLL = 8
SB_LEFT = 6
SB_RIGHT = 7
SB_LINELEFT = 0
SB_LINERIGHT = 1
SB_PAGELEFT = 2
SB_PAGERIGHT = 3
SB_THUMBPOSITION = 4
SB_THUMBTRACK = 5
End Enum