Differences between onok (), oncancel (), onclose (), and ondestroy ()

Source: Internet
Author: User

 

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.