Sign in to follow this  
Koen VB

Making window procedure a class member

Recommended Posts

Koen VB    133
I'm making a class that encapsulates a window. Now I want to make the window procedure a class member, like this: class CWindow { ... LRESULT CALLBACK WndProc(HWND HWindow, UINT Msg, WPARAM wParam, LPARAM lParam); } This function is used during the creation of the window class. WinClass.lpfnWndProc = (WNDPROC)WndProc; This results in the following error message: Error E2235: Member function must be called or its address taken in function CWindow::CWindow(...) One thing I tried was making the WndProc function static. This worked, but the problem was that you could no longer access non-static members of the class, while I really need access to them. Is there a way to use a member function of a class as a window procedure without making it static?

Share this post


Link to post
Share on other sites
SiCrane    11839
You can't assign a pointer to a non-static member function to a pointer to a normal function. The usual method to handle this is to assign a static or normal function to the windows procedure and use GetWindowLong() or GetWindowLongPtr() to a pointer from the GWL_USERDATA of the windows class. See this article for more details.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this