简体   繁体   English

CStatic子类别的Control无法接收输入消息

[英]CStatic subclassed Control fails to receive input messages

I am using a MFC dialog based application and have a subclassed CStatic control. 我正在使用基于MFC对话框的应用程序,并且具有子类的CStatic控件。 I would like to receive WM_MOUSEWHEEL and other messages inside my subclassed control but somehow those messages never arrive. 我想在我的子类控件中接收WM_MOUSEWHEEL和其他消息,但是以某种方式这些消息永远不会到达。

Here is how my Dialog looks like: 这是我的对话框的样子:

在此处输入图片说明

I'm only doing some really simple drawing and want to be able to move my list up and down by scrolling. 我只在做一些非常简单的绘图,并且希望能够通过滚动来上下移动列表。

I did already: 我已经做了:

  • Change the Tab-Order to ensure focus on the subclassed CStatic control first 更改Tab顺序以确保首先关注子类CStatic控件
  • Overwrote OnNcHitTest to give focus to the subclassed CStatic all the time 重写OnNcHitTest始终将焦点放在子类CStatic上
  • Added a scroll bar to the side 在侧面添加了滚动条
  • Wrote message handler for WM_MOUSEWHEEL, WM_LBUTTONDOWN, WM_KEYDOWN and WM_VSCROLL 为WM_MOUSEWHEEL,WM_LBUTTONDOWN,WM_KEYDOWN和WM_VSCROLL编写消息处理程序
  • Tried catching the messages in PreTranslateMessage 尝试在PreTranslateMessage捕获消息

Sadly nothing ever gets called when I'm scrolling inside the Dialog / Pressing a key or clicking with my mouse. 可悲的是,当我在对话框中滚动/按一个键或用鼠标单击时,什么也没有被调用。 The messages just don't arrive. 消息只是没有到达。

Here is my Mousewheel handler for example: 例如,这是我的Mousewheel处理程序:

class CFolderView : public CStatic
{
   ...
   afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
   DECLARE_MESSAGE_MAP()
   ...
}

BEGIN_MESSAGE_MAP(CFolderView, CStatic)
    ON_WM_MOUSEWHEEL()
    ON_WM_KEYDOWN()
    ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()

BOOL CFolderView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
    MessageBox("Mouse Wheel moved!", "Debug", MB_OK);

    return CStatic::OnMouseWheel(nFlags, zDelta, pt);
}

I fail to understand why no input messages are being sent to my subclassed control. 我不明白为什么没有输入消息被发送到我的子类控件。 Is there some switch that enables input for a subclassed control? 是否有一些开关可以启用子类控件的输入?

You cannot handle WM_MOUSEWHEEL in CStatic because it cannot get focus by design. 您无法在CStatic处理WM_MOUSEWHEEL ,因为它无法通过设计获得焦点。

From MSDN: 从MSDN:

The WM_MOUSEWHEEL message is sent to the focus window when the mouse wheel is rotated 旋转鼠标滚轮时,WM_MOUSEWHEEL消息将发送到焦点窗口

By looking at your screenshot I'd suggest subclassing CListBox instead. 通过查看您的屏幕截图,我建议改为CListBox

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM