I post this answer to help people who are in the same situation as me.
1. Introduction
Interaction with the scrollbar can be can be done using (It’s probably not the only methods that exist):
- SetScrollPos coupled with ScrollWindow. The first scrolls the bare scroll, the second scrolls the contents of the window
- ScrollToPosition which scrolls both the scroll bare and the contents of the window
The first method (SetScrollPos coupled with ScrollWindow) requires management of all scrollbar informations : scrollable size, current position, ... and recalculate it on each OnSize () (which is not too trivial ...)
With the seconde method (ScrollToPosition) mode, all we have to do is to call the ScrollToPosition
with the desired scrolling size. We don't have to manage the details of the scroll bare, Windows does it for us!
For some reason that I don't know, the stylus
scroll functionality on Windows 10
does not have the same behavior on Windows 7
: The scrollbar scrolls but not the contents of the window !!!
2. Solution
Having spent several hours on this problem, I conclude that the simple solution to work around this problem is to use the ScrollToPosition function as much as possible. And in this case, you just need to calculate scrolled size (delta
) which is defined by:
All you have to do is call the ScrollToPosition
function with the calculated delta
. This will allow you to move from an extremely complicated management mode to a few things that look like this:
ON_WM_LBUTTONDOWN
void CMyView::OnLButtonDown (UINT nFlags, CPoint point)
{
// Code here ...
POINT p;
GetCursorPos(&p);
ScreenToClient ( &p); // Convert to screen coordinates
m_dragPosition = p; // m_dragPosition : member variable to store click position
m_bMouseDown = true; // Set Flag to true
CWnd::OnLButtonDown (nFlags, point) ;
}
ON_WM_LBUTTONUP
void CMyView::OnLButtonUp (UINT nFlags, CPoint point)
{
// Code here ...
m_bMouseDown = false;
CWnd::OnLButtonUp(nFlags, point);
}
ON_WM_MOUSEMOVE
void CMyView::OnMouseMove(UINT nFlags, CPoint point)
{
int delta = p.y - m_dragPosition.y;
// Use absolute value to take into account top/bottom scrolling
if ( abs (delta) > SCROLLING_STEP_SIZE)
{
CPoint pp = GetScrollPosition (); // Get current scrollbar position
pp.y += -delta;
pp.x = 0; // I'm intersting only for vertical scrolling
ScrollToPosition (pp); // Scroll to new position
UpdateWindow (); // This redraw new showed area
m_dragPosition = p; // Update drag position
}
}
By adding this, you avoid explicit management which is not at all trivial...
Hope this will help those who are in the same situation as me