I'm currently coding an application that needs to catch every action done by the user on his window handle.
I needed the following event to be raised:
- Window resized, maximized, minimized or moved
- User changed the active window
- User changed the window handle's keyboard focused
To do that, I tried a lot of solutions, but in vain. First, I used a Timer that poll every 100ms the foreground window (using GetForegroundWindow() ) and the keyboard focused handle using AttachThreadInput() coupled with GetFocus() function.
But this solution was not very convenient and I prefered a cleaner solution using UIAutomation provided by .NET Framework. But I realized it used a lot of CPU and was too slow for my purpose, and the event was called sometimes 3 or 4 times when I switched to another window handle.
Concerning window resize, maximize, etc. I did a timer as well (but not very truthful), and tried to get working some Hooking technics like CBT hook and Shell hook. Unfortunately, I found that this kind of hook (global hook) isn't supported by C#.
I'm looking for a stable and reliable code for this part of my program. Thanks in advance.