Program closing
-
How could I handling the process of 'Program closing' using Visual C++ (MFC) I want the program to 'decide' how to quit or when to quit.
You have to override the WM_QUIT and WM_CLOSE messages. The WM_QUIT message is the one that terminates the entire application. WM_CLOSE is sent when exiting a window such as a dialog. An example of how to manually quit the program would be PostMessage(WM_QUIT, 0, 0) Similarly WM_CLOSE can be used as well. Hope that helps.
-
You have to override the WM_QUIT and WM_CLOSE messages. The WM_QUIT message is the one that terminates the entire application. WM_CLOSE is sent when exiting a window such as a dialog. An example of how to manually quit the program would be PostMessage(WM_QUIT, 0, 0) Similarly WM_CLOSE can be used as well. Hope that helps.
-
It doesn't work when I tried to override WM_CLOSE message in my view class. It seems that the system did not send WM_CLOSE message to my CView class when the prgram started to terminate.
Hmm. I'll try to help you out more, although I don't know that much about overriding those messages as I've never done it before. I've only worked with closing the program in a dialog based app. The code I posted before should work for manually closing the program. I don't see why it would be any different in an SDI. I'd suggest working with the WM_QUIT message first since that is the message sent when the program terminates. As far as I know the WM_CLOSE message is used if you have for instance a pop-up dialog and want to close it, so it shouldn't be sending any WM_CLOSE messages upon termination of the entire program.
-
Hmm. I'll try to help you out more, although I don't know that much about overriding those messages as I've never done it before. I've only worked with closing the program in a dialog based app. The code I posted before should work for manually closing the program. I don't see why it would be any different in an SDI. I'd suggest working with the WM_QUIT message first since that is the message sent when the program terminates. As far as I know the WM_CLOSE message is used if you have for instance a pop-up dialog and want to close it, so it shouldn't be sending any WM_CLOSE messages upon termination of the entire program.
-
Hmm. I'll try to help you out more, although I don't know that much about overriding those messages as I've never done it before. I've only worked with closing the program in a dialog based app. The code I posted before should work for manually closing the program. I don't see why it would be any different in an SDI. I'd suggest working with the WM_QUIT message first since that is the message sent when the program terminates. As far as I know the WM_CLOSE message is used if you have for instance a pop-up dialog and want to close it, so it shouldn't be sending any WM_CLOSE messages upon termination of the entire program.
-
I used spy++ to trace messages of my program, but did not get any WM_QUIT message. So I'm afraid if it would take effect if I work with the WM_QUIT message.
Well I'm pretty sure that's what happens when you press the big orange 'X' button. Try this and you'll see what it does. In any of the drop down menus you have create an option called "Quit" and in the code just put PostMessage(WM_QUIT, 0, 0); That will quit the entire app.