Foreground Window Detection Detection

I know that with GetForegroundWindow I can get the current active window handle, but now i want to detect when the active window (of any application) changes (become active) . the first solution that comes to my mind is

  • save the current value (handle) returned by the GetForegroundWindow function.
  • using the timer component again check the value returned by GetForegroundWindow and compare it with the old value.

I am wondering if there is a better way to do this, perhaps using a Windows message or something else.

+7
source share
1 answer

Use SetWindowsHookEx to set the CBT hook. MSDN describes callback function

+7
source

Source: https://habr.com/ru/post/1276896/


All Articles