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?
LVL 4
AssafLavieAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SteHCommented:
Unless all the childs, etc are not getting there messages directly there is no simple way. To speed things up messages can be routed directly to controls and don't need to go via the main dialog in which case you will loose them. An approach may be to peek into the main application queue and find get the corresponding messages from there. Only be aware of performance issues with that approach.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AssafLavieAuthor Commented:
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.
0
SteHCommented:
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.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

AssafLavieAuthor Commented:
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.
0
AssafLavieAuthor Commented:
(I just noticed that I already posted my objection to using global hooks in my original post...)
Still, thanks for helping out.
0
SteHCommented:
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.
0
AssafLavieAuthor Commented:
Sure, but then if new children are created I would be unware, unless I re-enumerate them periodically.
0
SteHCommented:
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.  
0
AssafLavieAuthor Commented:
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".
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.