Crash during WM_NCCREATE

This is a discussion on Crash during WM_NCCREATE within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I'm trying to write an custom control and I'm experiencing some problems. I have a class Button, derived from ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    34

    Question Crash during WM_NCCREATE

    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);
        }
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,338
    > if(msg = WM_NCCREATE)
    Why is this not == ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    34
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hooking Crash?
    By Elysia in forum Windows Programming
    Replies: 9
    Last Post: 03-15-2008, 01:13 PM
  2. Can not debug a crash
    By hannibar in forum Windows Programming
    Replies: 2
    Last Post: 06-30-2007, 10:02 AM
  3. Dynamic array sizing causes crash
    By Mithoric in forum C++ Programming
    Replies: 3
    Last Post: 12-30-2003, 06:46 AM
  4. FYI: asctime(gmtime(&mytime)) = crash!
    By anonytmouse in forum C Programming
    Replies: 2
    Last Post: 09-29-2003, 02:24 AM
  5. Crash after crash!
    By Dual-Catfish in forum C++ Programming
    Replies: 1
    Last Post: 03-31-2002, 08:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21