如何捕获 CListCtrl 中的滚动事件?
我将 CListCtrl 子类化为我自己的类,并在多个对话框和视图中使用它。我想要做的是当 ClistCtrl 垂直滚动时执行一些代码。我需要将其放在 CListCtrl 子类本身中。
我可以使用 democodemonkey 提供的方法检测与滚动条交互时触发的滚动:
messagemap:
BEGIN_MESSAGE_MAP(CMyListCtrl, CListCtrl)
ON_WM_VSCROLL()
END_MESSAGE_MAP()
方法声明:
class CMyListCtrl : public CListCtrl
{
//...
protected:
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
DECLARE_MESSAGE_MAP()
};
方法实现:
void CMyListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
//do some stuff here
CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
}
但是:
鼠标滚轮滚动不会触发 OnVSroll。
自动滚动发生 当 CListCtrl 项目部分 单击底部可见(它 向上滚动,因此该项目是 完全可见)没有触发 OnVScroll 也可以。例如:
单击项目 9 会使 ClistCtrl 滚动一点,以便该项目完全可见。
I subclassed CListCtrl into my own class, and I use it in several dialogs and views. What I want to do is execute some code when the ClistCtrl is being scrolled vertically. I need this to be in the CListCtrl subclass itself.
I can detect the scrolling triggered when interacting with the scrollbar with the method provided by demoncodemonkey:
messagemap:
BEGIN_MESSAGE_MAP(CMyListCtrl, CListCtrl)
ON_WM_VSCROLL()
END_MESSAGE_MAP()
method declaration:
class CMyListCtrl : public CListCtrl
{
//...
protected:
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
DECLARE_MESSAGE_MAP()
};
method implementation:
void CMyListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
//do some stuff here
CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
}
But:
Mousewheel scrolling does not trigger
OnVScroll.The automatic scrolling happening
when a CListCtrl item partially
visible at the bottom is clicked (it
is scrolled up so the item is
entirely visible) did not trigger
OnVScroll either. For example:
Clicking on item 9 causes the ClistCtrl to scroll a little so the item is completely visible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
消息映射:
方法声明:
方法实现:
messagemap:
method declaration:
method implementation:
鼠标滚轮滚动触发OnMouseWheel。
Mousewheel scrolling trigger OnMouseWheel.
更好的解决方案是使用发送到父窗口的
LVN_BEGINSCROLL
或LVN_ENDSCROLL
通知。 (它们还考虑了鼠标滚轮滚动。)尽管这仍然不能解决用户使用键盘上下移动焦点列表项时发生的滚动问题。
A much better solution is to use
LVN_BEGINSCROLL
orLVN_ENDSCROLL
notifications that are sent to the parent window. (They also account for mouse-wheel scrolling.)Although that still doesn't solve the scrolling that occurs when a user moves the focused list item up and down using keyboard.