问题
I have an MFC application that works fine with Pen (Stylus) under Windows 7, but unfortunately, it does not work on Windows 10.
- Under Windows 7, I am able to scroll vertically with the stylus WITHOUT using (clicking and dragging) the scroll bar, i can scroll vertically by clicking and dragging from anywhere in my dialog (formview)
- Under Windows 10, I am not able to scroll vertically with the stylus WITHOUT using (clicking and dragging) the scroll bar. I must click (and drag) with the Stylus on the scroll bar to scroll vertically
My need :
I need to be able to scroll vertically with the stylus WITHOUT using (clicking and dragging) the scroll bar on Windows 10
Detail:
I am on Windows 10 with Visual studio 2010.
My opinion
I think that the version of MFC100.dll (related to my Visual Studio 2010) does probably not support the functionality of the stylus under Windows 10 because the code works correctly under windows 7
Someone has already encountered this problem ? Thanks.
回答1:
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:
- Starts when the mouse button is pressed (Stulys pointed) (use ON_WM_LBUTTONDOWN)
- Extended/reduced during drag (use ON_WM_MOUSEMOVE)
- Ends when the button is released (use ON_WM_LBUTTONUP)
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
来源:https://stackoverflow.com/questions/62024461/windows-10-pen-stylus-not-working-on-mfc-application