Jump to content
  • Advertisement
Sign in to follow this  
Funkymunky

subclass to a class member function?

This topic is 3799 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
Advertisement
ah. I looked up pointers to member functions, and found out basically that I shouldn't be trying to do this. My mix of class functions and globals will have to do for now. thanks

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!