Hi, I'm trying to create a generic callback to use for my custom widgets, seeing as I pass control out to a class to keep it object oriented I need to create a callback for each individual widget however the only difference between each callback is the type of each class.
Example:
So for each new widget I create I have to create a new wndproc and change WIDGETINFO and that's all, because the proc member of the WIDGETINFO handles the messages and everything to keep this all really modular and easy to handle.Code:LRESULT CALLBACK wndproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){ WIDGETINFO* p = (WIDGETINFO*)GetWindowLong(hwnd, 0); if(p){ return p->proc(hwnd, msg, wParam, lParam); }else{ p = new WIDGETINFO; SetWindowLong(hwnd, 0, p); } return DefWindowProc(hwnd, msg, wParam, lParam); }
Could I use polymorphism? I dunno, probably not because I need to change "new WIDGETINFO" ???
Umm, I had attempted using a templated function but I wasn't really confident about it before I did it and it failed as I had predicted.
My problem hinges [with the templated approach] in passing the type specifier for the lpfnWndProc member of the WNDCLASS struct when registering it.



LinkBack URL
About LinkBacks


