简体   繁体   English

OnKillFocus()在奇数次触发MFC时覆盖

[英]OnKillFocus() override in MFC triggering at odd times

I need to know when my Window goes out of input focus, so I overloaded the OnKillFocus() method of the CWnd. 我需要知道我的Window何时没有输入焦点,所以我重载了CWnd的OnKillFocus()方法。

However it doesn't invoke this method when I focus another application (alt+tab), or even minimize the window. 但是,当我关注另一个应用程序(alt + tab)或甚至最小化窗口时,它不会调用此方法。 But it DOES invoke the method when I restore it from being minimized. 但是当我从最小化恢复它时,它会调用该方法。 Are these the intended times for it to trigger this method? 这些是触发此方法的预期时间吗?

如果您需要确保在应用程序关闭时收到通知,我认为您需要一个CWnd :: OnActivateApp()处理程序。

OnKillFocus() is normally only used consistently for controls that have a concept of gaining the focus - buttons, edit boxes, list boxes, etc. Normally CWnd does not accept the focus, so you can't rely on that - I'm surprised you get it at all. OnKillFocus()通常仅用于具有获得焦点概念的控件 - 按钮,编辑框,列表框等。通常CWnd不接受焦点,所以你不能依赖它 - 我很惊讶你得到它。

In addition to WM_ACTIVATEAPP mentioned above, there's also WM_ACTIVATE when switching between windows within the same application you might want to trap. 除了上面提到的WM_ACTIVATEAPP之外,在您可能想要捕获的同一应用程序中的窗口之间切换时,还有WM_ACTIVATE

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

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