为什么子窗口不能接收鼠标事件?
我有一个自定义 WTL 控件,它是一个带有列表和自定义滚动条的面板。
class Panel
: public ATL::CWindowImpl<Panel>, public WTL::CDoubleBufferImpl<Panel> {
public:
DECLARE_WND_CLASS("Panel")
BEGIN_MSG_MAP_EX(Panel)
MSG_WM_CREATE(OnCreate)
MSG_WM_DESTROY(OnDestroy)
MSG_WM_SIZE(OnSize)
CHAIN_MSG_MAP(CDoubleBufferImpl<Panel>)
REFLECT_NOTIFICATIONS()
END_MSG_MAP()
滚动条是由 OnCreate() 中的面板创建的:
m_scrollBar.Create(m_hWnd, WTL::CRect(...));
该滚动条在许多其他对话框窗口中工作正常。 但是,在该面板控件内会出现滚动条,但根本不接收鼠标事件。 如果我将 WM_MOUSEMOVE 处理程序添加到面板,它就会被调用。
可能是什么问题呢?
I have a custom WTL control which is a panel with a list and a custom scroll bar.
class Panel
: public ATL::CWindowImpl<Panel>, public WTL::CDoubleBufferImpl<Panel> {
public:
DECLARE_WND_CLASS("Panel")
BEGIN_MSG_MAP_EX(Panel)
MSG_WM_CREATE(OnCreate)
MSG_WM_DESTROY(OnDestroy)
MSG_WM_SIZE(OnSize)
CHAIN_MSG_MAP(CDoubleBufferImpl<Panel>)
REFLECT_NOTIFICATIONS()
END_MSG_MAP()
The scroll bar is created by the panel in OnCreate():
m_scrollBar.Create(m_hWnd, WTL::CRect(...));
That scroll bar works fine in many other dialog windows. However, inside that panel control the scroll bar appears, but receives no mouse events at all. If I add WM_MOUSEMOVE
handler to the panel, it does get called.
What could be the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
诊断 Windows 消息传递问题的一个好方法是使用 Spy++ 或 Winspector,它允许您获取深入了解 Windows 消息传递。
A good way to diagnose problems with Windows messaging is to use Spy++ or Winspector which allow you to get an under-the-covers look at Windows messaging.
找到了。 问题出在滚动条类声明中:
更改为:
使滚动条在面板上工作。
Found it. The problem was in the scroll bar class declaration:
Changing to:
makes the scroll bar work on the panel.