1

我有一个 MFC 应用程序,可以在 Windows 7 下与 Pen ( Stylus ) 配合使用,但不幸的是,它不适用于 Windows 10。

  • Windows 7下,我可以在不使用(单击并拖动)滚动条的情况下使用触控笔垂直滚动,我可以通过从对话框中的任意位置单击并拖动来垂直滚动(表单视图)
  • Windows 10下,我无法在不使用(单击并拖动)滚动条的情况下使用触控笔垂直滚动。我必须使用滚动条上的触控笔单击(并拖动)才能垂直滚动

我的需要:
我需要能够在不使用(单击并拖动)Windows 10 上的滚动条的情况下使用触控笔垂直滚动

详细信息:
我在装有 Visual Studio 2010 的 Windows 10 上。

我的观点
我认为MFC100.dll的版本(与我的 Visual Studio 2010 相关)可能不支持 Windows 10 下手写笔的功能,因为代码在 Windows 7 下可以正常工作

有人已经遇到过这个问题吗?谢谢。

4

1 回答 1

0

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

于 2020-06-08T09:02:37.997 回答