subclass to a class member function?
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?
This document does something similar to what you want, it should give you enough information for what you need:
Creating a Win32 Window Wrapper Class
Creating a Win32 Window Wrapper Class
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
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
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; }};
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement