subclassing and wm_notify msgs from subclassed window

subclassing and wm_notify msgs from subclassed window

Post by titu » Thu, 25 Jul 2002 15:26:39



My goal is to "wrap" a common control and provide my own functionality
that augments/changes that of the common control. After reading about
subclassing extensively, it is clear that with the Get/SetWindowLong
functions you can easily handle ONE DIRECTION of message flow; namely,
the flow of messages INTO the control (i.e. you catch messages on the
way in and either handle them, forward them on to the underlying
control window proc, or both).

But what about the messages coming OUT of the "wrapped" control (like
WM_NOTIFY messages). WM_NOTIFY messages are sent to the parent window,
but I sure would like my "subclass" window procedure to see them, and
then be able to handle them or pass them "up" to the parent myself; i.e.
flow of messages the other way.

This is really a very useful idea. For example, I would like to
have a treeview control that displays a certain image for an "expanded"
tree as "default" behavior -- by that I mean that the writer of an app
using my treeview just has to create it as a child to one of his windows,
but doesn't have to worry about handling the WM_NOTIFY message that
contains the TVM_EXPANDED message -- I would like my custom control to
catch the WM_NOTIFY that is on its way back to the parent. That way, I
can do the image changing and THEN forward that message to the parent
so he can do what he wants in addition to the image changing...

I think that this behavior (full wrapping of a control) can be done
by creating a "container" window that is the parent of the subclassed
control, correct? Is this the right way to do it? It seems like it might
be a pain -- how do I make sure that the container never gets
in the way; i.e. that it is always the same size, position, as
the child, etc? If this is the way to do it, can someone give me
very general direction?

I was hoping that it could be done without having to explicitly
create another window just to be a container and "upward message
catcher" for the wrapped control -- it seemed like subclassing
might get me there, but the subclassed window talks directly back
to the parent instead of to my new window proc. Is there a way
to make subclassing work?

Thanks,
Steve T.

 
 
 

subclassing and wm_notify msgs from subclassed window

Post by Stephane Heber » Sun, 28 Jul 2002 01:54:58


Steve,

Quote:> I was hoping that it could be done without having to explicitly
> create another window just to be a container and "upward message
> catcher" for the wrapped control -- it seemed like subclassing
> might get me there, but the subclassed window talks directly back
> to the parent instead of to my new window proc. Is there a way
> to make subclassing work?

Subclassing is what you need.  Remember that you can subclass any class as
long as it supplies a handle.

So when your control gets created, the owning window will give it it's
handle right ?  There's your chance to subclass the wndproc of the owning
window.

Steph

 
 
 

1. if I subclass, must I un-subclass before destroying?

When I subclass a control in a dialog box, I'm always careful to un-subclass
the control again before closing the dialog box (i.e. at EndDialog).

In Petzold's HEAD.C example (page 263-267), he subclasses a listbox, but
never restores the old proc before processing WM_DESTROY.

Is this:
  (a) perfectly ok
  (b) sloppy, but ok
  (c) dangerous/wrong
  (d) other

My guess is (b). Comments?
--

Airborne Geophysics
Geological Survey of Canada, Ottawa

2. Almost Newbie..

3. finding old window proc of subclassed window

4. Can Pinnacle do VideoCD

5. Subclassing Desktop Window in W95

6. ISP's and WPP's - help

7. Subclassing a window in another application?

8. Admin Rights on Workstations

9. Painting a subclassed window

10. Subclassing an out-of-process window

11. Subclassing a window from a different process

12. Window Hooking/Subclassing Problem

13. How to find whether a window is subclassed or not??