Subclassing a window 
Author Message
 Subclassing a window

Hi all,

A newbie question I'm sure but how do you subclass a window using
CWnd::SubclassWindow ?

I get an assert in a method called by SubclassWindow:

BOOL CWnd::SubclassWindow(HWND hWnd)
{
 if (!Attach(hWnd))
  return FALSE;

BOOL CWnd::Attach(HWND hWndNew)
{
 ASSERT(m_hWnd == NULL);     // only attach once, detach on destroy <<
ASSERT HERE!!!!
 ASSERT(FromHandlePermanent(hWndNew) == NULL);
  // must not already be in permanent map

It seems it's already been subclassed?

Thanx for any insight
Sham



Sat, 16 Apr 2005 03:02:41 GMT  
 Subclassing a window

Quote:

> Hi Jeff,

> Well I want to intercept some messages going to my CWnd derived class and
> handle them directly, perhaps passing them on. Is there another way to do
> this?

Well my first response is to state that that's what the MESSAGE_MAP is for, and the MESSAGE_MAP is
why MFC has already subclassed the HWND to the CWnd. What part of this scheme doesn't work for you?

--
Jeff Partch [MVP]



Sat, 16 Apr 2005 03:23:22 GMT  
 Subclassing a window
Hi Jeff,

Well I want to intercept some messages going to my CWnd derived class and
handle them directly, perhaps passing them on. Is there another way to do
this?

Thanx for any ideas

Mark



Quote:
> > Hi all,

> > A newbie question I'm sure but how do you subclass a window using
> > CWnd::SubclassWindow ?

> > I get an assert in a method called by SubclassWindow:

> > BOOL CWnd::SubclassWindow(HWND hWnd)
> > {
> >  if (!Attach(hWnd))
> >   return FALSE;

> > BOOL CWnd::Attach(HWND hWndNew)
> > {
> >  ASSERT(m_hWnd == NULL);     // only attach once, detach on destroy <<
> > ASSERT HERE!!!!
> >  ASSERT(FromHandlePermanent(hWndNew) == NULL);
> >   // must not already be in permanent map

> > It seems it's already been subclassed?

> Yes, its already been subclassed as far as MFC is concerned. What are you

trying to accomplish?

- Show quoted text -

Quote:

> --
> Jeff Partch [MVP]



Sat, 16 Apr 2005 03:15:31 GMT  
 Subclassing a window
I want to intercept messages meant for one class (A) with another (B).
Obviously I have my reasons for this. For example, I want to get the right
click sent to class A sent first to my proxy class B. Then I will send it on
to class A as needed.

Mark



Quote:
> > Hi Jeff,

> > Well I want to intercept some messages going to my CWnd derived class
and
> > handle them directly, perhaps passing them on. Is there another way to
do
> > this?

> Well my first response is to state that that's what the MESSAGE_MAP is

for, and the MESSAGE_MAP is
Quote:
> why MFC has already subclassed the HWND to the CWnd. What part of this

scheme doesn't work for you?
Quote:

> --
> Jeff Partch [MVP]



Sat, 16 Apr 2005 03:34:13 GMT  
 Subclassing a window

Quote:

> I want to intercept messages meant for one class (A) with another (B).
> Obviously I have my reasons for this. For example, I want to get the right
> click sent to class A sent first to my proxy class B. Then I will send it on
> to class A as needed.

See if something like Paul DiLascia's CSubclassWnd is what you have in mind...

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

--
Jeff Partch [MVP]



Sat, 16 Apr 2005 04:13:35 GMT  
 Subclassing a window
I will check it out.
Thanx Jeff!



Quote:
> > I want to intercept messages meant for one class (A) with another (B).
> > Obviously I have my reasons for this. For example, I want to get the
right
> > click sent to class A sent first to my proxy class B. Then I will send
it on
> > to class A as needed.

> See if something like Paul DiLascia's CSubclassWnd is what you have in
mind...

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

> --
> Jeff Partch [MVP]



Sat, 16 Apr 2005 05:34:49 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Subclassing foreign window and changing memory in it

2. Subclassing a window in different process

3. Problems subclassing a window

4. Subclassing a window in another application?

5. Subclassing a Window

6. subclassing a window

7. Subclassing MFC windows

8. Subclassing System.Windows.Forms.ListBox

9. Subclassing window

10. Subclassing window

11. Subclassing Problem with Unicode Windows

12. Q: subclassing problem, with hook and windows messages

 

 
Powered by phpBB® Forum Software