而用户拖动列表视图项检测滚动时有必要 [英] Detect when scrolling is necessary while user drags listview items
问题描述
我采取的列表视图项目清理不使用OLE拖放。
I am implementing rearranging of listview items without using OLE drag and drop.
我已经成功地解决了大部分这个任务,除了滚动向上/向下,当用户想要在这个当前不可见的位置掉落物品。
I have successfully solved most of this task, except scrolling up/down when user wants to drop items at the position that is not currently visible.
我能够通过以下消息来向上/向下滚动列表视图:
I am able to scroll up/down listview by using following messages:
SendMessage(hwndListView, WM_VSCROLL, (WPARAM)SB_LINEUP, (LPARAM)0);
SendMessage(hwndListView, WM_VSCROLL, (WPARAM)SB_LINEDOWN, (LPARAM)0);
我需要搞清楚你的建议的何时何地的我需要发送这些邮件(我想这应该WM_MOUSEHOVER或类似的东西做什么?)。
I need your advice in figuring out when and where I need to send those messages ( I suppose it should be done on WM_MOUSEHOVER or something like that? ).
我只是不知道哪些信息,以及如何,如果需要滚动我应该检查。
的我感兴趣的实施默认滚动的拖放行为。的
我曾尝试使用列表视图命中测试,所以我可以检查的 LVHITTESTINFO为 LVHT_ABOVE
>和 LVHT_BELOW
,但没有为我工作。
I have tried to use listview hit testing so I can examine LVHITTESTINFO for LVHT_ABOVE
and LVHT_BELOW
but that did not work for me.
的我从来没有能够在列表视图点击时要获取这些值... 的
我发现在使用定时器来实现这个其他编程语言的一些例子。我学习他们为我写这个帖子。
I have found some examples in other programming languages that use timers to implement this. I am studying them as I write this post.
列表视图是在报告模式,并支持多选。
Listview is in report mode and supports multiselection.
我处理下列消息:
LVN_BEGINDRAG // I create drag image here
WM_MOUSEMOVE // I update drag image here
WM_LBUTTONUP // I rearrange items here and perform cleanup
我省略SSCCE保持这个职位短。如果需要,我可以将它张贴。如果需要进一步的信息,请发表评论。
I have omitted SSCCE to keep this post short. If needed I can post it. If further info is required please leave a comment.
推荐答案
presumably您拖放循环使用 SetCapture
来捕获鼠标输入。
Presumably your drag and drop loop uses SetCapture
to capture mouse input.
所有你需要做的就是观看 WM_MOUSEMOVE
消息。当上面的顶部或下方的列表视图底部的鼠标移动,设置一个标志,表明你正在滚动,并使用启动一个定时器的SetTimer
。
All you have to do is watch for WM_MOUSEMOVE
messages. When the mouse moves above the top or below the bottom of the listview, set a flag to indicate you are scrolling and start a timer using SetTimer
.
每当定时器熄灭,滚动在适当的方向一条线,通过发送列表视图一个 WM_VSCROLL
消息。
Every time the timer goes off, scroll one line in the appropriate direction, by sending the listview a WM_VSCROLL
message.
如果鼠标在列表视图内移回,或捕捉丢失(即你获得 WM_CAPTURECHANGED
),杀死你的计时器和停止滚动。
If the mouse moves back inside the listview, or the capture is lost (i.e. you get WM_CAPTURECHANGED
), kill your timer and stop scrolling.
这篇关于而用户拖动列表视图项检测滚动时有必要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!