Solved

subclass a hierarchy of windows

Posted on 2004-10-26
221 Views
Last Modified: 2010-08-05
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?
0
Question by:AssafLavie
    9 Comments
     
    LVL 13

    Accepted Solution

    by:
    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
     
    LVL 4

    Author Comment

    by:AssafLavie
    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
     
    LVL 13

    Expert Comment

    by:SteH
    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
     
    LVL 4

    Author Comment

    by:AssafLavie
    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
     
    LVL 4

    Author Comment

    by:AssafLavie
    (I just noticed that I already posted my objection to using global hooks in my original post...)
    Still, thanks for helping out.
    0
     
    LVL 13

    Expert Comment

    by:SteH
    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
     
    LVL 4

    Author Comment

    by:AssafLavie
    Sure, but then if new children are created I would be unware, unless I re-enumerate them periodically.
    0
     
    LVL 13

    Expert Comment

    by:SteH
    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
     
    LVL 4

    Author Comment

    by:AssafLavie
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
    In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    877 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now