You cannot use a non-static class method as a window procedure callback. The parameter list is not compatible due to the hidden this
pointer. What you have to do instead is:
In
BaseWindow
, define a static method as the actual message callback registered withRegisterClassEx()
, and then define a separate virtual method for processing messages. Have theBaseWindow
implementation of the virtual method callDefWindowProc()
, and descendants that override the virtual method need to call the base method for unhandled messages.Pass the object's
this
pointer as thelpCreateParam
ofCreateWindow/Ex()
.In the
WM_NCCREATE
message handler, retrieve thelpCreateParam
value from the message and assign it to the HWND using eitherSetWindowLongPtr(GWL_USERDATA)
orSetProp()
, then type-cast the value to aBaseWindow*
pointer and use it to call the virtual method.For subsequent messages, use
GetWindowLongPtr(GWL_USERDATA)
orGetProp()
to retrieve theBaseWindow*
pointer from the HWND and use it to call the virtual method.