Thread: Over Rideing close message when closing window

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    Over Rideing close message when closing window

    I have a window and than I have a child of that window wich is just anouther window. (Not a special like a button). But when I close the child window it closes the main window as well and shuts down the process. Is it possible to make that not hapen and only cloes the child window, I was thinking overridding the wm_close message or somthing.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Maybe, don't call PostQuitMessage in the WM_DESTROY message for the child window?

    Otherwise, could you post the code?

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Ahh ok that worked great. It's amazing how people can't think of the simplest solutions.

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    I figured out that isn't working. The child window uses the class of the main window, so I'm not sure how to not call PostQuitMessage in WM_DESTROY of the child sence the WM_DESTROY gets sent to the same message proc.

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    if (hwnd == hwndParent) PostQuitMessage(0);
    or, if you don't store the parent hwnd in a variable, you can just check if the hwnd is a parent window:
    Code:
    if (GetParent(hwnd) == NULL) PostQuitMessage();

  6. #6
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    ok but when I do that, no windows show up. But if I take out the if statment the windows show up. huh?

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    The if statement should be in the WM_DESTROY message:
    Code:
    case WM_DESTROY:
    {
        if (GetParent(hwnd) == NULL) PostQuitMessage();
        break;
    }

  8. #8
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    heres my code:

    Code:
            case WM_DESTROY:
    			if (hwndwindow == hwnd)
    			{
    				PostQuitMessage(0);
    			}
                break;
    were hwndwindow is the paramter in the callback and hwnd is my parent window.

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    You could also create a seperate class and wndproc for child windows.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange string behavior
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 07:38 PM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. Making a script language?
    By Blackroot in forum Game Programming
    Replies: 10
    Last Post: 02-16-2006, 02:22 AM
  4. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  5. window message help!
    By jdude in forum C++ Programming
    Replies: 2
    Last Post: 05-16-2004, 08:05 AM