Exiting program from secondary dialog

This is a discussion on Exiting program from secondary dialog within the Windows Programming forums, part of the Platform Specific Boards category; Okay, I have a main window that is created on startup. Then with the press of a button, it goes ...

  1. #1
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    Exiting program from secondary dialog

    Okay, I have a main window that is created on startup. Then with the press of a button, it goes into a dialog box to do everything, etc. But, I want to have an option in the menu of the dialog box to EXIT the whole program. How would I do this? What would the code be to destroy the main window and exit the program all from the dialog box?

    Thanks!
    1978 Silver Anniversary Corvette

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Return a value from EndDialog() which specifies that the application should be closed.
    Code:
    nRet = DialogBox( ... );
    if (MY_CLOSE_VALUE == nRet) PostMessage(hwndMain, WM_DESTROY, ...);
    OR

    Try sending WM_CLOSE or WM_DESTROY to the main window after calling EndDialog().
    Code:
    EndDialog( ... );
    PostMessage(hwndMain, WM_DESTROY, ...);

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    And that will stop the process of the application as well as destroy the window(s)?

    And, using that PostMessage function in the dialog procedure, that means I'm going to have to get the handle to the main window somehow..?
    1978 Silver Anniversary Corvette

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    If the dialog is a child of the main window, you could use GetParent

    Otherwise, you could store the handle to the main window in a place where the dialog can reach it....just a little careful planning and it's easy

  5. #5
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Originally posted by anonytmouse
    Return a value from EndDialog() which specifies that the application should be closed.
    Code:
    nRet = DialogBox( ... );
    if (MY_CLOSE_VALUE == nRet) PostMessage(hwndMain, WM_DESTROY, ...);
    OR

    Try sending WM_CLOSE or WM_DESTROY to the main window after calling EndDialog().
    Code:
    EndDialog( ... );
    PostMessage(hwndMain, WM_DESTROY, ...);
    This worked perfectly! Thanks!!
    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 01:59 PM
  2. How to prevent exiting from running program
    By scorpio_IITR in forum Linux Programming
    Replies: 5
    Last Post: 01-18-2004, 03:15 AM
  3. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 08:48 AM
  4. exiting program
    By spike232 in forum C# Programming
    Replies: 4
    Last Post: 05-25-2002, 08:18 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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