Hi,
I'm trying to write an custom control and I'm experiencing some problems. I have a class Button, derived from a CustomControl class. In my button class I have defined message router function for passing the messages to my message handler class member function. The thing here is I want to use a window message processer for each instance of the control that is created. (Is this a stupid way of doing things? I mean, I could have passed in a pointer to the class instance in each message handler, but then the code would be sprinkled with pointer->class_member all over).
The problem is my code crashes during WM_NCCREATE. If i return TRUE from RoutMsg() the progam seems to crash at that very moment. If i leave it out, it crashes when calling DefWindowProc() in Button::ButtonProc().
I am a bit puzzeled as to why this happens. Can someone shed some light on this?
Here's my message router function:
Code:
static LRESULT CALLBACK RouteMsg(HWND hwnd, UINT msg, WPARAM w, LPARAM l)
{
Button *btn = reinterpret_cast<Button *>(::GetWindowLongPtr(hwnd, GWL_USERDATA));
if(msg = WM_NCCREATE)
{
CREATESTRUCT *pcs = reinterpret_cast<CREATESTRUCT *>(l);
btn = reinterpret_cast<Button *>(pcs->lpCreateParams);
::SetWindowLongPtr(hwnd, GWL_USERDATA, reinterpret_cast<LONG_PTR>(btn));
btn->m_handle = hwnd;
//return TRUE; //If I uncomment this line the program crashes here
}
if(btn)
return btn->ButtonProc(hwnd,msg,w,l);
else
return DefWindowProc(hwnd,msg,w,l);
}
Code:
LRESULT Button::ButtonProc(HWND hwnd, UINT msg, WPARAM w, LPARAM l)
{
switch(msg)
{
default:
return DefWindowProc(hwnd,msg,w,l);
}
}