保持键盘焦点 [英] Keeping Keyboard Focus
本文介绍了保持键盘焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何确保基于C ++ / MFC对话框的应用程序在运行时保持键盘焦点?我尝试使用SetWindowPos()使主窗口位于最顶层,但是虽然它仍然位于其他窗口的顶部,但如果有人试图激活另一个应用程序,它仍然会失去键盘焦点。我必须点击我的应用程序标题栏才能重新获得键盘焦点。
谢谢
Tony
How can I ensure that my C++/MFC dialog based application keeps keyboard focus when it is running? I have tried making the main window topmost using SetWindowPos() but although it stays on top of other windows, it still looses keyboard focus if someone tries to activate another application. I have to click on my application's title bar to regain keyboard focus.
Thanks
Tony
推荐答案
你应该放松一个人激活另一个窗口的焦点,这是唯一有效的行为。您需要了解每个桌面只有一个聚焦窗口(子窗口,一个控件)。
但是,如果你认为焦点应该回到当窗口被激活时,以前集中控制,你是绝对正确的。
高级UI库总是会照顾它,但MFC不是其中之一。您可以通过处理Windows消息来实现此效果WM_ACTIVATE: https ://msdn.microsoft.com/en-us/library/windows/desktop/ms646274%28v=vs.85%29.aspx [ ^ ]。
使用MFC,您可以使用CWin:OnActivate
:https://msdn.microsoft.com/en-us/library/1f31c334.aspx [ ^ ]。
祝贺4月1日! :-)
我想利用这个机会邀请你(以及其他所有人)看到我4月份新出版的1并有一些乐趣:
某些编程方法神经语言程序设计 。
特别鼓励在评论和讨论中参与此游戏。
谢谢。
-SA
You are supposed to loose focus of someone activates another window, this is the only valid behavior. You need to understand that there is only one focused window (child window, a control) per desktop.
However, if you think that the focus should get back to the previously focused control when a window is activated, you are absolutely right.
High-level UI libraries always take care of that, but MFC is not one of them. You can achieve this effect by handling windows message WM_ACTIVATE: https://msdn.microsoft.com/en-us/library/windows/desktop/ms646274%28v=vs.85%29.aspx[^].
With MFC, you can useCWin:OnActivate
: https://msdn.microsoft.com/en-us/library/1f31c334.aspx[^].
Congratulations with April 1st! :-)
I would like to use the occasion to invite your (and everyone else, of course) to see my new 1 of April publication and have some fun:
Some Programming Approaches to "Neuro-Linguistic Programming".
Participation in this game in Comments and Discussions is especially encouraged.
Thank you.
—SA
这篇关于保持键盘焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文