class CWindow {public: CWindow();private: void init(); HWND mHandle; static std::map<HWND, CWindow*> msThisMap; static long FAR PASCAL staticWndProc(...); long instanceWndProc(...);};// during some CWindow::CWindow() { init();}void CWindow::init() { // pass the static WndProc callback WNDCLASS wc; wc.lpfnWndProc = &staticWndProc RegisterClass(wc); // associate the HWND with a this pointer HWND mHandle = CreateWindowEx(...); if (!mHandle) { throw "ahhhhhhhhhhhhh!"; } msThisMap[mHandle] = this;}long CWindow::staticWndProc(HWND hwnd, UINT msg, UINT wParam, UINT lParam) { // retrieve the CWindow* pointer that was stored in init() CWindow* thisPointer = msThisMap[mHandle]; // dispatch the call to the correct instance return thisPointer->instanceWndProc(msg, wParam, lParam);}
That code sample is far from complete, and is probably incorrect in a few places since I pretty much did it from memory, but it should give you an idea of how to accomplish your goal. It's a hack, but hacks are all you have.
edit: code /code tags don't handle templates
[edited by - Dobbs on March 18, 2003 10:21:12 AM]