Making WinProc a member function

Started by
10 comments, last by Evil Steve 17 years, 11 months ago
Quote:Original post by clb
My implemenation does just that - the global WndProc is a friend of the class, and calls a private WndProc of the application class. I don't know if there's a "better" way to do it, but this method is the simplest and most straightforward to use.
I too do it this way.

I like trampolines[smile]

F-R-E-D F-R-E-D-B-U-R...G-E-R! - Yes!
Advertisement
My site is down unfortunately, so I can't link you to my article, but what I do is something like this:
// Header file: class CWindow{public:   // ...private:   static LRESULT CALLBACK StaticWndProc(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam);   LRESULT WndProc(UINT umsg, WPARAM wparam, LPARAM lparam);protected:   HWND m_hWnd;   // ...};// Source file:LRESULT CALLBACK CWindow::StaticWndProc(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam){CWindow* pParent;   if(umsg == WM_NCCREATE)   {      pParent = ((CREATESTRUCT*)lParam)->lpCreateParams;      SetWindowLongPtr(hWnd, GWL_USERDATA, (LONG_PTR)pParent);   }   else   {      pParent = (CWindow*)GetWindowLongPtr(hWnd, GWL_USERDATA);   }   if(pParent) return pParent->WndProc(umsg, wparam, lparam);   else return DefWindowProc(hWnd, usmg, wparam, lparam);}

And then you use StaticWndProc when you set up your WNDCLASS structure. You also need to use CreateWindowEx and pass this as the last parameter. Note that code is just off the top of my head and may not be accurate...

This topic is closed to new replies.

Advertisement