Link to home
Start Free TrialLog in
Avatar of AssafLavie
AssafLavie

asked on

subclass a hierarchy of windows

I want to intercept (via subclassing or hooking) all messages that are destined to some window and all of it's descendent windows (children, grand children, etc.)
Is there a way of doing it without hooking the entire desktop or subclassing every child window recuresively?
ASKER CERTIFIED SOLUTION
Avatar of Member_2_1001466
Member_2_1001466

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AssafLavie
AssafLavie

ASKER

Sorry for taking so long to reply.
No, I'm afraid I can't just monitor the application window. For one thing, I'm not talking about a single application for which I want to intercept messages. I'm talking about child window in general - not just controls on dialogs.
I want to be able choose a window arbitrarily in Windows (ignoring for the moment process permission issues) and be able to get notification for every messages that passes to it or to any of its children. One way of doing this is to go and sublcass each child in the hierachy.. but this isn't a good solution for several reasons. That's why I'm wondering it there's a proper way of doing this.
In that case you can hook to the global message queue and filter all messages for a window, or a set of windows and process them before the application sees them.
Yes, well I'm aware of that option, but:
1. a global hook is somewhat of a radical solution which I don't like to implement unless I really have no alternative.
2. If I do use a global hook I still need to decide for each window if it's a descendent of the given window, for example by repeatedly calling GetParent.

But mainly I want to refrain from using a global hook. It's overkill.
(I just noticed that I already posted my objection to using global hooks in my original post...)
Still, thanks for helping out.
I fear you need to go the unwanted route.

>2. If I do use a global hook I still need to decide for each window if it's a descendent of the given window, for example by repeatedly calling GetParent.
Here it should be easier to get all childs of a window once and put them into a list/vector/array. In hook handler you just go through this list.
Sure, but then if new children are created I would be unware, unless I re-enumerate them periodically.
You could try api hooking to get informed if windows are closed or created. Or since you hooked the global queue you could check in addition to messages with a certain HWND all WM_CREATE and WM_CLOSE. That way you should be aware of newly created windows and when windows of interest get destroyed.  
Yes, I know. But this only demonstrates why I don't like the idea of global hooking. What I'm looking for is a way to subclass a hierarchy of windows by performing some action on its root window - without having to resort to global hooking.
But thanks again for your input. I guess the answer to my question is basically "no".