Create and destroy a non-Modal Dialog Box

Source: Internet
Author: User
1. Create a non-Modal Dialog Box Create a non-Modal Dialog Box Code Generally:
 
Cyourdlg * pdlg = new cyourdlg; pdlg-> Create (idd_dlg_your, this); pdlg-> showwindow (sw_show );
 
Line 01 --- create cyourdlg dialog box object line 02 --- create dialog box window and associate it with the dialog box object created in Line 01. This specifies row 03 of the parent window of the dialog box-display window. Obviously, when releasing the dialog box, ensure that the cyourdlg dialog box objects are released, the dialog box that is associated with the release. In this way, there will be no memory leakage.
  2. Destruction of the non-Modal Dialog Box  compared with the modal dialog box, the creation and destruction processes differ from those of the modal dialog box, let's take a look at the original article of msdn: When you implement a modeless dialog box, always override the oncancel member function and call destroywindow from within it. don't call the base class cdialog: oncancel, because it callenddialog, which will make the dialog box invisible but will not destroy it. you shoshould also override postncdestroy for modeless dialog boxes in order to delete this, since modeless dialog boxes are usually allocated with new. modal Dialog Boxes are usually constructed on the frame and do not need postncdestroy cleanup. 
  1. in the non-modal dialog box, override onok and oncancel call destroywindow.  purpose: to release the dialog box 
 protected: virtual void onok (); Virtual void oncancel (); void cyourdlg: onok () {This-> destroywindow ();} void cyourdlg: oncancel () {This-> destroywindow () ;}
2. in the non-modal dialog box, override postncdestroy and call delete this . Objective: To release the cyourdlg dialog box object
 protected: Virtual void postncdestroy (); void cyourdlg: postncdestroy () {cdialog: postncdestroy (); Delete this ;} 
 the destruction process is as follows: destroywindow () sends two messages: wm_destroy and wm_ncdestroy. The processing function of the wm_ncdestroy message in the message ing table of cwnd is afx_msg void onncdestroy (). You can see the cwin_message_map (cwnd, c0000target) of the cwnd class )...... on_wm_ncdestroy ()...... end_message_map () onncdestroy calls the virtual void postncdestroy (); 

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.