0

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?

Community
  • 1
  • 1
mwKART
  • 885
  • 2
  • 9
  • 18
  • referred this link( http://stackoverflow.com/a/511350/3341400 ) to learn to use GetActiveWindow() or GetForegroundWindow() – mwKART Nov 23 '15 at 15:49
  • [WM_KILLFOCUS is the wrong time to do field validation](http://blogs.msdn.com/b/oldnewthing/archive/2004/04/19/115912.aspx). – IInspectable Nov 23 '15 at 16:46

1 Answers1

0

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.

mwKART
  • 885
  • 2
  • 9
  • 18