I am wondering if it is possible to subclass a window from within a class. Consider the following class:
Now, I realize this is not a complete class. I cannot get a function pointer to the MsgHandler function of the class. I realize this is because Windows wants (requires?) that the callback function be a global function and not an instance function, but is there some way around this? If not then I have to have a global MsgHandler and store all the hWnds and function pointers in global arrays and I really don't want to do this. If there is a way to pull off what I am trying to do, can somebody please let me know how.Code:class Base { public: Base() {} virtual ~Base() {} BOOL Subclass(HWND hWnd) { long lpfnNewProc = (long)this->MsgHandler; //<-- This is my error long lpfnOldProc = SetWindowLong(hWnd, GWL_WNDPROC, lpfnNewProc); return TRUE; } LRESULT CALLBACK MsgHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { // Do something with the message return 0; } };
Thanks




Reply With Quote