拖动时自动滚动 [英] Automatic scroll while dragging

查看:172
本文介绍了拖动时自动滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管是一位古老的程序员,但我对MFC和Windows编程还是没有足够的经验.我正在尝试在拖动过程中添加自动滚动. CScrollView窗口具有此功能,但我希望能够将其添加到具有内置滚动条的任何旧窗口中(使用WS_VSCROLL样式).最简单的方法似乎是当光标位于窗口顶部或底部附近的区域上时,发送WM_VSCROLL消息.我天真地以为像

Though an ancient programmer, I''m still fairly inexperienced in MFC and Windows programming in general. I''m trying to add automatic scrolling during dragging. CScrollView windows have this feature, but I want to be able to add it to any old window with built-in scrollbars (using WS_VSCROLL style). The easy way appears to be to send a WM_VSCROLL message when the cursor is over an area near the top or bottom of the window. I naively assumed that something like

SendMessage(WM_VSCROLL, SB_LINEDOWN);


也许可以,但是它似乎并没有传递到右边的窗口,大概是子窗口,即滚动条.然后我以为可以找到子窗口的句柄,然后将消息发送给该子窗口.尝试了各种方法,例如


might work, but it does not seemed to be passed on to the right window, presumably a child window that is the scroll bar. Then I thought that I could find a handle for the child window, and send the message to that. Tried various approaches, like

GetDescendantWindow(SB_VERT)
GetWindow(GW_CHILD)


但似乎没有任何东西可以使我访问滚动条.我发现使它起作用的唯一方法是使用


but nothing seems to give me access to the scroll bar. The only way I have found to make it work is to use

SendMessageToDescendants(WM_VSCROLL, SB_LINEUP);


这似乎很不雅致,因为所有子窗口都必须处理仅针对其中一个窗口的消息.

因此,我想知道的是:您能获得内置滚动条的句柄吗?如果是这样,怎么办?如果没有,为什么不呢?有人可以建议任何更好的方法来将自动滚动添加到任意窗口类型吗?


which seems inelegant, in that all child windows will have to process the message that is only aimed at one of them.

So what I would love to know is: can you get a handle to the built-in scroll bars? If so how; if not, why not? And can anyone suggest any better ways to add automatic scrolling to an arbitrary window type?

推荐答案

是否可以向拖动到的窗口中添加OnMouseOver事件?您将设置一个属性,以指示已在OnDragEnter中开始拖动到窗口中,并在OnDragDrop和OnDragAbort中重置此属性.

在鼠标悬停事件中,您现在可以检查指示正在进行拖放操作的属性,并且如果光标位于窗口的顶部或底部附近,则窗口可以采取措施沿所需方向滚动. >
好吧,希望这能给您一些想法,并可以帮助您实现它.

祝你好运!
Could you add an OnMouseOver event to the window you drag into? You would set a property to indicate that dragging into the window has started in the OnDragEnter and reset this property in the OnDragDrop and OnDragAbort.

In the mouse over event you could now check the property that indicates if a dragdrop operation is going on is and if the cursor is near the top or bottom of the window, the window could take action to scroll in the desired direction.

Well, hopfully this gives you some idea and can help you implement it.

Good luck!


GetScrollBarInfo api将为您提供有关滚动条的信息,您只需将包含滚动条的窗口控件的句柄传递给它即可:

http://msdn.microsoft.com/en-us/library/bb787581% 28VS.85%29.aspx [ ^ ]
它返回此结构:
http://msdn.microsoft.com/en-us/library/bb787535% 28VS.85%29.aspx [ ^ ]
还有Get/SetScrollInfo,GetSetScrollPos和GetSetScrollRange函数:
GetScrollInfo: http://msdn.microsoft.com/en-us/library/bb787583%28VS.85%29.aspx [ ^ ]
GetScrollPos: http://msdn.microsoft.com/en-us/library/bb787585%28VS.85%29.aspx [ ^ ]
GetScrollRange: http://msdn.microsoft.com/en-us/library/bb787587%28VS.85%29.aspx [ ^ ]
SetScrollInfo: http://msdn.microsoft.com/en-us/library/bb787595%28VS.85%29.aspx [ ^ ]
SetScrollPos: http://msdn.microsoft.com/en-us/library/bb787597%28VS.85%29.aspx [ ^ ]
SetScrollRange: http://msdn.microsoft.com/en-us/library/bb787597%28VS.85%29.aspx [ ^ ]
并且ScrollWindow api应该允许您滚动:
http://msdn.microsoft.com/en-us/library/bb787591% 28VS.85%29.aspx [ ^ ]


希望这些链接都能帮助您按照自己喜欢的方式进行滚动:)
The GetScrollBarInfo api will get you information about a scrollbar, you can just pass it the handle of the window control that holds the scrollbar:

http://msdn.microsoft.com/en-us/library/bb787581%28VS.85%29.aspx[^]
It returns this struct:
http://msdn.microsoft.com/en-us/library/bb787535%28VS.85%29.aspx[^]
There are also the Get/SetScrollInfo, GetSetScrollPos and GetSetScrollRange functions:
GetScrollInfo: http://msdn.microsoft.com/en-us/library/bb787583%28VS.85%29.aspx[^]
GetScrollPos: http://msdn.microsoft.com/en-us/library/bb787585%28VS.85%29.aspx[^]
GetScrollRange: http://msdn.microsoft.com/en-us/library/bb787587%28VS.85%29.aspx[^]
SetScrollInfo: http://msdn.microsoft.com/en-us/library/bb787595%28VS.85%29.aspx[^]
SetScrollPos: http://msdn.microsoft.com/en-us/library/bb787597%28VS.85%29.aspx[^]
SetScrollRange: http://msdn.microsoft.com/en-us/library/bb787597%28VS.85%29.aspx[^]
and the ScrollWindow api should allow you to just scroll:
http://msdn.microsoft.com/en-us/library/bb787591%28VS.85%29.aspx[^]


Hopefully these links all help you to handle the scrolling the way you like it :)


这篇关于拖动时自动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆