陷阱在MFC对话框中输入关键消息 [英] Trapping Enter key messages in a MFC dialog
问题描述
HI,
我有一个MFC对话框,它是一个父窗口.此对话框包含几个子窗口,它们是具有其他子控件(例如按钮,编辑框等)的对话框.我的问题是,无论哪个子对话框处于活动状态,无论哪个,都需要更改Enter键的默认行为.子对话框中的子控件具有焦点,在按Enter键(VK_RETURN
)时,必须通知父窗口我可以根据需要对其进行处理的地方.
当焦点放在子控件上时,在这种情况下,PreTranslateMessage()
失败.解决此问题的最佳方法是什么?使用ProcessMessageFilter()
是否会提高性能?
你们当中有人可以指导我吗?示例代码将非常有帮助.
谢谢大家.
I have a MFC dialog which is a parent window. This dialog contains several child windows which are dialogs themseleves having other child controls like button, edit box etc. My problem is that I need to change the default behaviour of the Enter key such that, no matter which child dialog is active and no matter which child control within the child dialog has the focus, on press of the Enter key (VK_RETURN
), the parent window must be notified where I can handle it as I want.
PreTranslateMessage()
fails for this scenario when the focus is on child control. What is the best way to tackle this problem? Would using ProcessMessageFilter()
hit the performance?
Can any of you guide me on this? Sample code would be really helpful.
Thanks all...
推荐答案
您可以安装挂钩来捕获VK_RETURN
密钥,然后再将其分发到活动窗口中.
您可以在 MSDN库中找到更多信息(请参阅 http ://msdn.microsoft.com/zh-CN/library/ms644990(VS.85).aspx [
You can install an hook to trap theVK_RETURN
key before it is dispatched to the active window.
You can find more informations on the MSDN library (see http://msdn.microsoft.com/en-us/library/ms644990(VS.85).aspx[^] and related resources).
See the additional resources aboutWH_KEYBOARD
andKeyboardProc
callback procedure.
这篇关于陷阱在MFC对话框中输入关键消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!