WM_CHAR和WM_KEYDOWN在CWnd的派生类中没有响应 [英] WM_CHAR and WM_KEYDOWN no respond in CWnd's derived class

查看:108
本文介绍了WM_CHAR和WM_KEYDOWN在CWnd的派生类中没有响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码是我用来创建窗口资源的代码.我发现WM_RBUTTONDOWN响应但是WM_CHAR和WM_KEYDOWN没有响应.我也使用CWnd :: CreateEx并再次失败.
CWnd :: Create(NULL,_T("ReportCtrl"),dwStyle,rect,pParentWnd,nID);

The code below is which I used to create window resource.I found WM_RBUTTONDOWN respond but WM_CHAR and WM_KEYDOWN not.I also used CWnd::CreateEx and failed again.
CWnd::Create(NULL, _T("ReportCtrl"), dwStyle, rect, pParentWnd, nID);

推荐答案

键盘焦点.此外,它取决于一种窗口.如果这是一个控件,则应该在按键时集中并集中.如果这是其中包含可聚焦控件的弹出窗口,则可以通过其中的一个控件来获取焦点.您可以将键盘处理程序添加到每个控件或预览键盘消息.

有关更多信息,请参见 http://msdn.microsoft.com/zh-我们/library/ms646267(v=vs.85).aspx [
This indicates that the windows in question does not have a keyboard focus. Further, it depends on a kind of window. If this is a control, if should be focusable and focused at the moment of key press. If this is a popup window having focusable controls in it, the focus can be grabbed by one of there controls. You can add keyboard handlers to each control or preview keyboard messages.

For more information, see http://msdn.microsoft.com/en-us/library/ms646267(v=vs.85).aspx[^].

—SA


这里有很多可能性...

我会怎么做:

1.首先检查是否正在发送消息.您可以使用Spy ++(Visual Studio作为附加应用程序提供)进行此操作.

2.一旦确定邮件已发送:
-确保在代码中放置了正确的消息处理程序.消息是总是"发送的,因此很可能您没有处理它们.
-检查您的应用程序中是否还有其他窗口正在处理这些消息,从而捕获它们,然后阻止您的窗口处理它们.根据消息的处理方式,它们会在处理程序功能中死亡...

希望对您有所帮助.
There are lots of possibilities here...

What I would do:

1. First check if the messages are being sent or not. You can do this using Spy++ (it comes with visual studio as an extra app).

2. Once you are sure that the messages are being sent:
- Ensure that you''ve placed the right message handlers in your code. Messages are "always" sent, so it is possible that you are not handling them.
- Check if any other window in your app is handling those messages, thus capturing them and then preventing your windows to handle them. Depending on the way the messages are handled they die at the handler function...

Hope this helps.


我解决了这个问题.解决方案就是SAKryukov所说的,为什么我不能做到这一点,是因为我使用了错误的方法来将窗口设置为可聚焦的. WM_SETFOCUS只是一条消息,用于证明窗口具有焦点,但无法设置窗口焦点.要设置一个具有焦点的窗口,功能SetFocus可以做到.
I solved this problem. The solution is what SAKryukov had said, and why I couldn''t do it is I used the wrong way to set the window focusable. WM_SETFOCUS is just a message to prove the window has focus but can''t set the window focusalbe. To set one window has focus, the function SetFocus can do it.


这篇关于WM_CHAR和WM_KEYDOWN在CWnd的派生类中没有响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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