Share via


WM_VSCROLL (Compact 2013)

3/28/2014

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

Syntax

WM_VSCROLL nScrollCode = (int)LOWORD(wParam); 
    nPos = (short int)HIWORD(wParam); 
    hwndScrollBar = (HWND) lParam;

Parameters

  • nScrollCode
    Value of the low-order word of wParam. Specifies a scroll bar value that indicates the user's scrolling request. It is one of the following values.

    Value

    Description

    SB_BOTTOM

    Scrolls to the lower right

    SB_ENDSCROLL

    Ends scroll

    SB_LINEDOWN

    Scrolls one line down

    SB_LINEUP

    Scrolls one line up

    SB_PAGEDOWN

    Scrolls one page down

    SB_PAGEUP

    Scrolls one page up

    SB_THUMBPOSITION

    The user has dragged the scroll box (thumb) and released the mouse button. The nPos parameter 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 nPos parameter indicates the position that the scroll box has been dragged to.

    SB_TOP

    Scrolls to the upper left

  • nPos
    Value of the high-order word of wParam. Specifies the current position of the scroll box if the nScrollCode parameter is SB_THUMBPOSITION or SB_THUMBTRACK; otherwise, nPos is not used.
  • hwndScrollBar
    If the message is sent by a scroll bar, then hwndScrollBar is the handle to the scroll bar control. If the message is not sent by a scroll bar, hwndScrollBar is NULL.

Return Value

An application should return zero if it processes this message.

Remarks

The SB_THUMBTRACK message 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.

When the range of scroll bar uses a non-zero value for the minimum position, SB_THUMBTRACK and SB_THUMBPOSITION notifications report the current position incorrectly. The SB_THUMBPOSITION maps the scroll bar range to 0 - (max-min). The following code example shows how to work around this problem by adding your minimum to the nPos value passed in with this message.

case WM_VSCROLL:
{
    int nScrollCode = (int)LOWORD(wParam);
    int nPos = (short int)HIWORD(wParam);
    SCROLLINFO si = {sizeof(SCROLLINFO), 
                     SIF_PAGE|SIF_POS|SIF_RANGE|SIF_TRACKPOS, 0, 0, 0, 0, 
                     0};
    GetScrollInfo (hWnd, SB_VERT, &si);
    int nNewPos = si.nPos;
    switch (nScrollCode)
    {
        // Include code that checks for other values of nScrollCode.
        // ...
        case SB_THUMBPOSITION:
          nNewPos = nPos + si.nMin; 
          break;
    }
    si.fMask = SIF_POS;
    si.nPos = nNewPos;
    SetScrollInfo (hWnd, SB_VERT, &si, TRUE);
}
return TRUE;

Note that the WM_VSCROLL message carries only 16 bits of scroll box position data. Thus, applications that rely solely on WM_VSCROLL (and WM_HSCROLL) 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

Header

winuser.h

See Also

Reference

Scroll Bar Messages
GetScrollInfo
SetScrollPos
SetScrollRange
WM_HSCROLL