Subclassing in MFC 
Author Message
 Subclassing in MFC

Is there any (legal) way of subclassing a window that is attached to a
(CWnd-derived) MFC object?

I was hoping to subclass a toolbar control (based on CToolbar and embedded
in a CFrameWnd) in order to intercept notification messages from a child
ComboBox, but evidently the mechanism provided by CWnd::SubclassWindow does
not allow for subclassing a window that is already attached to an MFC
object.
Is this definitely impossible, or is there another way? If subclassing is
not possible, is there another recommended approach (in MFC context) to
picking up the notification messages from a ComboBox (or any other child
control) sitting on a toolbar?

Thanks

Peter



Wed, 13 Jul 2005 18:54:40 GMT  
 Subclassing in MFC

Quote:
> Is there any (legal) way of subclassing a window that is attached to a
> (CWnd-derived) MFC object?

> I was hoping to subclass a toolbar control (based on CToolbar and
embedded
> in a CFrameWnd) in order to intercept notification messages from a
child
> ComboBox, but evidently the mechanism provided by CWnd::SubclassWindow
does
> not allow for subclassing a window that is already attached to an MFC
> object.
> Is this definitely impossible, or is there another way? If subclassing
is
> not possible, is there another recommended approach (in MFC context)
to
> picking up the notification messages from a ComboBox (or any other
child
> control) sitting on a toolbar?

Well, there's SetWindowLongPtr/GWLP_WNDPROC, and MSJ columnist Paul
DiLascia has a helper class called CSubclassWnd that he's been using
since circa 1997. As good a starting point for it as any is this URL to
his June 1997 C++ Q&A column...

http://www.microsoft.com/msj/defaultframe.asp?page=/msj/0697/c++0697.htm

--
Jeff Partch [VC++ MVP]



Wed, 13 Jul 2005 19:56:48 GMT  
 Subclassing in MFC
You should not have to subclass the toolbar for this. I think you should be
able to handle the notification in mainframe or any of the CCmdTarget
derived objects in routing chain.

--
Ajay Kalra [MVP - VC++]


Quote:
> Is there any (legal) way of subclassing a window that is attached to a
> (CWnd-derived) MFC object?

> I was hoping to subclass a toolbar control (based on CToolbar and embedded
> in a CFrameWnd) in order to intercept notification messages from a child
> ComboBox, but evidently the mechanism provided by CWnd::SubclassWindow
does
> not allow for subclassing a window that is already attached to an MFC
> object.
> Is this definitely impossible, or is there another way? If subclassing is
> not possible, is there another recommended approach (in MFC context) to
> picking up the notification messages from a ComboBox (or any other child
> control) sitting on a toolbar?

> Thanks

> Peter



Thu, 14 Jul 2005 07:14:50 GMT  
 Subclassing in MFC
Well, in addition to the other solutions proposed, you could just change the class name of
the variable in the CFrameWnd.
                                joe

Quote:

>Is there any (legal) way of subclassing a window that is attached to a
>(CWnd-derived) MFC object?

>I was hoping to subclass a toolbar control (based on CToolbar and embedded
>in a CFrameWnd) in order to intercept notification messages from a child
>ComboBox, but evidently the mechanism provided by CWnd::SubclassWindow does
>not allow for subclassing a window that is already attached to an MFC
>object.
>Is this definitely impossible, or is there another way? If subclassing is
>not possible, is there another recommended approach (in MFC context) to
>picking up the notification messages from a ComboBox (or any other child
>control) sitting on a toolbar?

>Thanks

>Peter

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Thu, 14 Jul 2005 08:07:44 GMT  
 Subclassing in MFC
Hi all
Thanks for the tips. I have derived my own class from CToolBar and
overridden its WindowProc. That works in any case. (Is that what Joe meant?)
But then Ajay had a point too. Indeed, when I tried his suggestion, it
worked!  It hadn't occurred to me that MFC's message-routing mechanism would
take care of it automatically. It just meant manually adding the message map
entry and handler as the wizard didn't recognise this event in this context.
Thanks one and all!

Peter


Quote:
> Is there any (legal) way of subclassing a window that is attached to a
> (CWnd-derived) MFC object?

> I was hoping to subclass a toolbar control (based on CToolbar and embedded
> in a CFrameWnd) in order to intercept notification messages from a child
> ComboBox, but evidently the mechanism provided by CWnd::SubclassWindow
does
> not allow for subclassing a window that is already attached to an MFC
> object.
> Is this definitely impossible, or is there another way? If subclassing is
> not possible, is there another recommended approach (in MFC context) to
> picking up the notification messages from a ComboBox (or any other child
> control) sitting on a toolbar?

> Thanks

> Peter



Thu, 14 Jul 2005 15:13:41 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. subclassing a MFC subclassed window

2. Subclassing Windows class in MFC

3. newbie: subclassing richedit in an ActiveX MFC ctl

4. MFC Subclassing

5. Subclassing Activex controls from commctrl (treectrl) in MFC

6. Subclassing (superclassing?) MFC control from commctrl (treectrl)

7. Subclassing MFC

8. MFC OCX Subclassing Problem

9. MFC Clist control subclassing

10. Subclassing MFC windows

11. US-TX-DFW DALLAS DEVELOPERS - Visual C++ / MFC / JUST ONE YEAR OF MFC ----MFC---MFC

12. Subclassing System.Web.UI.Page

 

 
Powered by phpBB® Forum Software