The framework calls this member function when the user clicks a vertically-aligned scroll bar, spin button control, or slider control.

afx_msg void OnVScroll( 
   UINT nSBCode, 
   UINT nPos, 
   CScrollBar* pScrollBar  


  • nSBCode
    Specifies a scroll-bar code that indicates the user's scrolling request. This parameter can be one of the following:

    • SB_BOTTOM   Scroll to bottom.

    • SB_ENDSCROLL   End scroll.

    • SB_LINEDOWN   Scroll one line down.

    • SB_LINEUP   Scroll one line up.

    • SB_PAGEDOWN   Scroll one page down.

    • SB_PAGEUP   Scroll one page up.

    • SB_THUMBPOSITION   Scroll to the absolute position. The current position is provided in nPos.

    • SB_THUMBTRACK   Drag scroll box to specified position. The current position is provided in nPos.

    • SB_TOP   Scroll to top.

  • nPos
    Specifies the current scroll-box position if the scroll-bar code is SB_THUMBPOSITION or SB_THUMBTRACK; otherwise, not used. Depending on the initial scroll range, nPos may be negative and should be cast to an int if necessary.

  • pScrollBar
    If the scroll message came from a scroll-bar control, a spin button control, or a slider control, this parameter contains a pointer to the control.

    If the user clicked a window's scroll bar, this parameter is NULL. The pointer may be temporary and should not be stored for later use.

    If the referenced control is either a spin button or a slider, you must cast the pointer to a CScrollBar*.


OnVScroll typically is used by applications that give some feedback while the scroll box is being dragged.

If OnVScroll scrolls the contents of the CWnd object, it must also reset the position of the scroll box with the SetScrollPos member function.


This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function.

When you click a spin button control, the value of nSBCode is SB_THUMBPOSITION.

The nPos parameter is a 16-bit value and must be used only for controls whose range value uses 16 bits or fewer.


Header: afxwin.h

See Also


CWnd Members


CWnd Class

Hierarchy Chart




Change History




July 2009

Added information about CSpinButtonCtrl and CSliderCtrl; specified nPos as 16-bit.

Customer feedback.