Archived

This topic is now archived and is closed to further replies.

WindowProc in a class

This topic is 5981 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm not really certain how to override this... Let's say we've got class "CApplication", with a member function, below:
  
LRESULT CALLBACK CApplication::WindowProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
}
  
... how is it possible to set up a WndClassEx structure such that the compiler will let you choose a class method ...
  
m_WndClassEx.lpfnWndProc = this->WindowProc;
                        or
m_WndClassEx.lpfnWndProc = CApplication::WindowProc;
  
... and not spit out a compiler error like ...
  
Cannot convert from 
'long (__stdcall CApplication::*)(struct HWND__ *, unsigned int, unsigned int, long)' to 
'long (__stdcall *)(struct HWND__ *, unsigned int, unsigned int, long)'
  
?? I can't seem to typecast the function pointer to anything (like __stdcall) because the compiler simply won't take it. Any suggestions are welcome. (And dealing with WindowProc() outside the CApplication class is not an option.) Thanks! Edited by - MatrixCubed on July 31, 2001 11:59:32 PM

Share this post


Link to post
Share on other sites
The only way you can do this is to make your WindowProc method static in your class.

This is due to the fact that a free function is not interchangeable to a member-function even though they take the same parameters and return the same type.

-Neophyte


- Death awaits you all with nasty, big, pointy teeth. -

Share this post


Link to post
Share on other sites
hi m8 try this

i''ve create an class for win controls the class have the static member method like these one WinControlProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);

and the code inside this method is like these, i route the arriving Window messages to an internal message handler method
with the same params like the WinControlProc method.

here the code inside WinControlProc :

LRESULT CALLBACK cWinControl::WinControlProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
cWinControl *pkWinControl = GetWinLong (hWnd);

switch (Msg)
{
case WM_NCCREATE :
{
cCreateData const *kCreateData = reinterpret_cast (lParam);
pkWinControl = static_cast (kCreateData->GetCreationData ());
SetWinLong (hWnd, pkWinControl);
}
break;

default :
{
if (pkWinControl)
return (pkWinControl->WinProc (hWnd, Msg, wParam, lParam));
}
break;
}
return (::DefWindowProc (hWnd, Msg, wParam, lParam));
}

GetWinLong and SetWinLong are templates, you can use the orginal Win API class if you want to do this work *g*

but don''t forget, when you create your application with CreateWindow or CreateWindowEx, set the "this" pointer to the last param, this is the extra create data.

if you want the source let me know :D

hoep this helps

Imp

Share this post


Link to post
Share on other sites