c++mfccedit

Bypass trigger of OnFocus/GetFocus event if the application window loses activation c++


I have a text box which take string value. On Focus lost it does a specific function (say function 1). But even if I lost focus on the window, this OnFocus event is getting triggered.

Suppose i have the following code :

classA::OnTextBoxFocus()
{
   CWnd* pCurrentFocus = GetFocus();

  // if focus event execute function 1

}

Now I want to put a check, to find out if the application window is active. Only if the Window is active, OnFocus event should get triggered.

I learned that using GetActiveWindow() or GetForegroundWindow() through the post "determine if the current window is the active window?(StackOverflow)"

However I am finding difficult it putting this check. Can you help me in understanding, how to implement, through an example?


Solution

  • I tried checking if the On focus event is NULL.

    classA::OnTextBoxFocus()
    {
       CWnd* pCurrentFocus = GetFocus();
    
      if(pCurrentFocus != NULL)
      // if focus event execute function 1
    
    }
    

    this is currently working as expected. Now I can bypass OnFocus event if change the current window.