Subclassing Windows 
Author Message
 Subclassing Windows

Hello,

Ive got a general question:

What is the difference between handling messages in a subclassed window
using i.e.

WCnd::SetWindowLong(pWndParent->m_hWnd, GWL_WNDPROC, (long)NewWindowProc);

and the normal MFC way:

ON_PAINT()
ON_ERASEBKGND()

I came across the first way when I tried to draw special childwindows in a
framewindow but didnt understand
why I couldnt simply use ON_PAINT() and so on...

Any idea?

    Steven



Tue, 27 Sep 2005 15:32:09 GMT  
 Subclassing Windows
MFC pretty much does the first thing using its own WindowProc (returned
by the AfxGetAfxWndProc() function). It is this WNDPROC that knows how
to look up entries in -- and route messages through, the message-map.
See CWnd::SubclassWindow(HWND hWnd).
--
Jeff Partch [VC++ MVP]


Quote:
> Hello,

> Ive got a general question:

> What is the difference between handling messages in a subclassed
window
> using i.e.

> WCnd::SetWindowLong(pWndParent->m_hWnd, GWL_WNDPROC,

(long)NewWindowProc);
Quote:

> and the normal MFC way:

> ON_PAINT()
> ON_ERASEBKGND()

> I came across the first way when I tried to draw special childwindows
in a
> framewindow but didnt understand
> why I couldnt simply use ON_PAINT() and so on...

> Any idea?

>     Steven



Tue, 27 Sep 2005 14:41:06 GMT  
 Subclassing Windows
Each MFC window is subclassed by default, and WndProc is routed into MFC core, and      
there messages are distributed using messages map.

That why you can use ON_PAINT()

In MFC you don't need subclassing, if you don't have reason.

Bredy



Tue, 27 Sep 2005 14:36:40 GMT  
 Subclassing Windows
But why cant I paint a background in a CMainFrame i.e. when I handle when I
overwrite OnEraseBkgnd().
It seems like it is painted grey again only a second later.



Quote:
> MFC pretty much does the first thing using its own WindowProc (returned
> by the AfxGetAfxWndProc() function). It is this WNDPROC that knows how
> to look up entries in -- and route messages through, the message-map.
> See CWnd::SubclassWindow(HWND hWnd).
> --
> Jeff Partch [VC++ MVP]



> > Hello,

> > Ive got a general question:

> > What is the difference between handling messages in a subclassed
> window
> > using i.e.

> > WCnd::SetWindowLong(pWndParent->m_hWnd, GWL_WNDPROC,
> (long)NewWindowProc);

> > and the normal MFC way:

> > ON_PAINT()
> > ON_ERASEBKGND()

> > I came across the first way when I tried to draw special childwindows
> in a
> > framewindow but didnt understand
> > why I couldnt simply use ON_PAINT() and so on...

> > Any idea?

> >     Steven



Tue, 27 Sep 2005 17:21:35 GMT  
 Subclassing Windows
Probably because the client area of the CMainFrame is covered either by
the CView or the MDI Client Window (which is usually grey). This is an
old document (and you can AFAIK safely ignore the GetSuperWndProcAddr
stuff), but it discusses these issues...

http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B103786

--
Jeff Partch [VC++ MVP]


Quote:
> But why cant I paint a background in a CMainFrame i.e. when I handle
when I
> overwrite OnEraseBkgnd().
> It seems like it is painted grey again only a second later.



> > MFC pretty much does the first thing using its own WindowProc
(returned
> > by the AfxGetAfxWndProc() function). It is this WNDPROC that knows
how
> > to look up entries in -- and route messages through, the
message-map.
> > See CWnd::SubclassWindow(HWND hWnd).
> > --
> > Jeff Partch [VC++ MVP]



> > > Hello,

> > > Ive got a general question:

> > > What is the difference between handling messages in a subclassed
> > window
> > > using i.e.

> > > WCnd::SetWindowLong(pWndParent->m_hWnd, GWL_WNDPROC,
> > (long)NewWindowProc);

> > > and the normal MFC way:

> > > ON_PAINT()
> > > ON_ERASEBKGND()

> > > I came across the first way when I tried to draw special
childwindows
> > in a
> > > framewindow but didnt understand
> > > why I couldnt simply use ON_PAINT() and so on...

> > > Any idea?

> > >     Steven



Tue, 27 Sep 2005 16:26:34 GMT  
 Subclassing Windows
Show the code. Also, is it MDI or SDI? If it is SDI, for examle, the window you see is not
the mainframe, but the view.
                                        joe

Quote:

>But why cant I paint a background in a CMainFrame i.e. when I handle when I
>overwrite OnEraseBkgnd().
>It seems like it is painted grey again only a second later.



>> MFC pretty much does the first thing using its own WindowProc (returned
>> by the AfxGetAfxWndProc() function). It is this WNDPROC that knows how
>> to look up entries in -- and route messages through, the message-map.
>> See CWnd::SubclassWindow(HWND hWnd).
>> --
>> Jeff Partch [VC++ MVP]



>> > Hello,

>> > Ive got a general question:

>> > What is the difference between handling messages in a subclassed
>> window
>> > using i.e.

>> > WCnd::SetWindowLong(pWndParent->m_hWnd, GWL_WNDPROC,
>> (long)NewWindowProc);

>> > and the normal MFC way:

>> > ON_PAINT()
>> > ON_ERASEBKGND()

>> > I came across the first way when I tried to draw special childwindows
>> in a
>> > framewindow but didnt understand
>> > why I couldnt simply use ON_PAINT() and so on...

>> > Any idea?

>> >     Steven

Joseph M. Newcomer [MVP]

Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm


Wed, 28 Sep 2005 06:04:54 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Subclassing Windows class in MFC

2. Subclassing Windows

3. Q: subclassing windows in other application

4. Subclassing windows

5. Help:ACIVEX controls- subclassing Windows Control

6. Subclassing Problem with Unicode Windows

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

8. Subclassing MFC windows

9. Subclassing System.Windows.Forms.ListBox

10. Subclassing System.Web.UI.Page

11. Subclassing Singleton

12. Subclassing the SQLDataReader class

 

 
Powered by phpBB® Forum Software