I'm trying to create a saveon exit capability for an SDI program. I currently use the destroywindow() function in the CMainFrame. I need to be able to save when the user clicks on the close X in the upper right hand corner of the program. While this approach works, the MainFrame has already disappeared before the MessageBox appears with the should the file be saved question . This looks unprofessional and I would like to have the message box appear before the MainFrame disappears. How do I do this?