如果应用程序窗口失去激活c++,则绕过OnFocus/GetFocus事件的触发器
Bypass trigger of OnFocus/GetFocus event if the application window loses activation c++
我有一个采用字符串值的文本框。在Focus丢失时,它执行特定的功能(比如功能1)。但即使我失去了对窗口的关注,这个OnFocus事件也会被触发。
假设我有以下代码:
classA::OnTextBoxFocus()
{
CWnd* pCurrentFocus = GetFocus();
// if focus event execute function 1
}
现在我想检查一下应用程序窗口是否处于活动状态。只有当窗口处于活动状态时,才应触发OnFocus
事件。
我通过帖子"确定当前窗口是否为活动窗口?(StackOverflow)"了解到使用GetActiveWindow()或GetForegroundWindow()
然而,我发现放这张支票很困难。你能通过一个例子帮助我理解,如何实现吗?
我尝试检查聚焦事件是否为NULL。
classA::OnTextBoxFocus()
{
CWnd* pCurrentFocus = GetFocus();
if(pCurrentFocus != NULL)
// if focus event execute function 1
}
这目前正在按预期进行。现在,如果更改当前窗口,我可以绕过OnFocus事件。