0

I've been messing around with some code, to allow for getting the Window Handle of a running process, and the handles of all child objects within it - e.g. running it against calc.exe gives the hWnd of calc, plus the handle of each button, etc, which is all straight foward enough. Alongside this, I'm using ProcessWatcher to watch for specific processes launching.

Now, where I'm having issues, is figuring out if it's possible to subscribe in some way, to be notified of the creation / deletion of Window Handles.

The intention is to use the 'new' Window Handle to get details about the object, and compare it to a list of items that the application should be watching for, e.g. the application would be sitting waiting for the notepad.exe process to launch, once it sees this process, it knows it should be watching out for a new window being created titled 'Save As', that is someone related to the notepad.exe process.

At the moment, the only way I can think of would be via a timer, after a short period, enumerate all Window Handles manually, sorting through them for what I want, but I'd imagine this would be very resource hungry, and inefficient.

Thanks in advance...

  • Does the answer to this question help you out any? http://stackoverflow.com/questions/79111/net-c-getting-child-windows-when-you-only-have-a-process-handle-or-pid?rq=1 – dodexahedron Aug 01 '14 at 12:33
  • One solution is a CBT hook (`WH_CBT`). It doesn't work from a .NET application; you need a native DLL. But I'll bet there's some way to do this using UI Automation. Check the System.Windows.Automation namespace. Whatever you do, do *not* use that timer! :-) – Cody Gray - on strike Aug 01 '14 at 12:40
  • @CodyGray Are you sure we need a native dll? I believe .net dll is also fine. I've done other hooks which works pretty well with .net dll too. – Sriram Sakthivel Aug 01 '14 at 13:19

0 Answers0