Crash during WM_NCCREATE
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:
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
LRESULT Button::ButtonProc(HWND hwnd, UINT msg, WPARAM w, LPARAM l)
> if(msg = WM_NCCREATE)
Why is this not == ?
Haha! I don't believe this! Thanks for pointing that out! I guess that's the way it is when I'm using multiple programming languages with different syntaxes. It gets confusing.. It also was very late last night ;)
Anyway, thanks! Changing to == of course sorted out the problem.