4

How could I detect when any application loses focus? Is there any system hooks to use? I want to pick up when ever a new application is in focus, or when one is lost. Even having the "current" HWND of the user would be good.

I am using C#, however, its all win api stuff I am sure... so any info would be great.

Mike Curry
  • 229
  • 1
  • 5
  • 9
  • Update I know I can use GetForegroundWindow() to get the current window HWND, I just want to subscribe to an event that will notify me of it changing. – Mike Curry Nov 12 '08 at 21:21

1 Answers1

5

Use SetWindowsHookEx to set either a WH_CALLWNDPROC or WH_CALLWNDPROCRET global hook, and look for WM_SETFOCUS and or WM_KILLFOCUS messages.

Tobias Kienzler
  • 25,759
  • 22
  • 127
  • 221
cookre
  • 321
  • 1
  • 2