Click to See Complete Forum and Search --> : window procedure


shai ostshega
May 23rd, 1999, 07:15 AM
Hi,

Is it possible to have a window procedure,that will be a member function of a class.

thanks,

Shai

Paul McKenzie
May 23rd, 1999, 10:56 AM
A static member function, yes it can be done. A non-static member function, no.

The prototype for a window procedure is not compatible with the prototype for a non-static class member function because of the hidden "this" argument for non-static member functions.

Regards,

Paul McKenzie

shai ostshega
May 24th, 1999, 01:14 AM
How does the message map macros map a message to
a class memeber function in MFC (for instance ON_MESSAGE(...) )?

Shai

Jason Teagle
May 24th, 1999, 02:19 AM
ON_MESSAGE(UM_MYMESSAGE, OnMyMessage)

maps to:

LRESULT CSomeWindowClass::OnMyMessage(WPARAM wParam, LPARAM lParam)
{
}

(the routine name OnMyMessage() can be whatever you want).

This mirrors the standard API window procedure where you have the parameters passed with the message and you return a long value.

Don't forget to stick afx_msg in front of the prototype in the header file.

RajM
May 24th, 1999, 06:21 PM
Hi,
In MFC there is a super window proc which is called for all the windows created using MFC .This is not a member of any class.its called AfxWndProcBase(file afxstate.cpp).This function in turn calls AfxWndProc which gets the CWnd pointer from the window handle which comes with the message and calls the member function of CWnd called WindowProc which in turn calls CWnd::OnWndMsg which finally calls the handler for that particular message which will be a member function of ur CWnd derived class.
The point is ur non-static member function is not a direct callback function.Its just been invoked by a real callback function(which is not a member of any class) which has the pointer to ur object.
Just put a breakpoint in a message handler and study the function call stack when it breaks at that point.