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 ();