Sign in to follow this  

subclass to a class member function?

This topic is 3490 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 have a c++ class that I use to encapsulate all the functionality for a particular common control. I subclass the control so as to custom draw it, but right now I have to pass it a standalone global function, not a member function of the class. How can I set the GWL_WNDPROC of my control to a public function of the class I'm using?

Share this post


Link to post
Share on other sites
You can use member functions as callbacks however you have to do a little trick...
What you can do is create a static member function (since it has the asme function signature as a regular C-function, and use that as a wrapper.. an example is for an EnumWindows callback.. you could do something like this


class Foo
{
public:
Foo() : Myhwnd(NULL) {}
~Foo() {}
Foo() : Myhwnd(NULL), ProcID(ProcessId) (unsigned long ProcessId)
{
EnumWindows((WNDENUMPROC)Wrapper, this);
}
inline HWND Get()
{
return Myhwnd;
}
protected:
HWND Myhwnd;
unsigned long ProcID;
static int __stdcall Wrapper(HWND hWnd, LPARAM lParam)
{
Foo* pFooObj = (Foo*)lParam;
return pFooObj->MemberCallback(hWnd);
}
int MemberCallback(HWND hWnd)
{
unsigned long PID = 0;
GetWindowThreadProcessId(hWnd, &PID);
if(PID == ProcId)
{
Myhwnd = hWnd;
return false;
}
else
return true;
}
};



Share this post


Link to post
Share on other sites

This topic is 3490 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.

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