First, onok () and oncancel () areMember functions of the cdialog base classWhile onclose () and ondestroy () areMember functions of the cwnd base classThat is, the WM message response function. Slave ApplicationProgramIn the dialog box, the red X corresponds to cwnd, while the "OK" and "cancel" buttons in the dialog box correspond to cdialog.
Second, onclose ():Message Response FunctionIn response to the wm_close message, this function is called when the "close" button is clicked (instead of when the dialog box we see disappears from the screen), and the user is responding to onok () or after the oncancel () function, wm_close messages are not sent.
Ondestroy ():Message Response FunctionTo respond to the wm_destroy message. When a window is about to be destroyed, it is sent.
In a single view program, according to <simple introduction to MFC>, the sequence of operations executed when the program exits is (starting from the point X button)
(1) The user clicks the X exit button and sends the wm_close message.-----> Response onclose ()
(2) In the wm_close message processing function, call destroywindow ()-----> Destroy the window associated with the specified cwnd window object, but the cwnd object is not destroyed
(3) The wm_destroy message is sent in destroywindow ().-----> Response to ondestroy () After window destruction ()
(4) Call postquitmessage () in the wm_destroy message to send the wm_quit message and end the message loop.
In summary, the program first calls onclose () (or may not call) and then calls ondestroy () (mandatory). Therefore,If you want to clean up the program at the end of the process, it should be in ondestroy () instead of onclose (), otherwise there may be a risk of Memory leakage.