The scroll bar common control allows you to specify scrolling range, scrolling position and scrolling page size. It does not allow you to specify the scrolling line size. If you want to increment/decrement the scrolling position on some value not equal to 1 when the up/down/left/right scroll bar button is pressed, then you should handle the button click event and change the scrolling position of the scroll bar common control manually.
You should handle the WM_HSCROLL
and WM_VSCROLL
messages exactly like the CExtScrollWnd
class does:
void CExtScrollWnd::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if( pScrollBar != NULL
&& pScrollBar->SendChildNotifyLastMsg()
)
return;
if( pScrollBar != GetScrollBarCtrl(SB_HORZ) )
return;
OnSwDoScroll( MAKEWORD( nSBCode, -1 ), nPos );
}
void CExtScrollWnd::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if( pScrollBar != NULL
&& pScrollBar->SendChildNotifyLastMsg()
)
return;
if( pScrollBar != GetScrollBarCtrl(SB_VERT) )
return;
OnSwDoScroll( MAKEWORD( -1, nSBCode ), nPos );
}
Then you should implement the
OnSwDoScroll()
method using the
CExtScrollWnd::OnSwDoScroll()
method as sample. You can see how the
CExtScrollWnd::OnSwDoScroll()
method handles the clicks on each part of the scroll bar common control.
In fact, you can simply use the
CExtScrollWnd
class as the base and very convenient class for implementing your own scrollable windows. You will simply need to implement the following virtual methods of the
CExtScrollWnd
class and the scrollable control will be ready to use:
virtual CSize OnSwGetTotalSize() const;
virtual CSize OnSwGetPageSize( int nDirection ) const;
virtual CSize OnSwGetLineSize( int nDirection ) const;
virtual void OnSwPaint( CDC & dc );
If you are using the MFC’s
CScrollView
class and document/view architecture in your project, then you can replace the
CScrollView
window with the
CView
window and a child
CExtScrollWnd
-based window in it.