views:

231

answers:

1

Is it possible to determine when window focus changes at the system level? I'm writing a time-tracking application, and I'd like to be able to listen for application switching (so that I can begin logging time in a given application). I've poked around the Process class for a good hour here, and while I learned quite a few useful things, I didn't find what I was looking for. I suspect I'll need to use hooks, but it's difficult finding clear documentation on the process, let alone documentation specific to what I'm asking.

+3  A: 

See SetWindowHooksEx.

Good article, "Windows Hooks in the .NET Framework":
http://msdn.microsoft.com/en-us/magazine/cc188966.aspx

Corey Trager
this is good, and very useful, but there are some holes in his article that I wish were filled--namely the implementation of the GetClassName() and GetWindowText() Win32 functions. If you can fill in some of those holes, I'd be grateful.
Brian Warshaw