Destruction of modal and non-modal windows

Source: Internet
Author: User

A few days ago, I found that my program uses the non-modal dialog box. The debug version has the following warning:

Warning: Calling destroywindow in cwnd ::~ Cwnd ondestroy or postncdestroy in derived class will not be called

Because it was warnning, I didn't care too much about it. Later I went online and found out that this problem was still very serious.

Finally, I have not figured out some basic problems. At the same time, I have learned a lot of new things in this process. There is a lot of information on this issue on the internet, and I feel that there are not many clear questions. I will give a summary today. I also want to answer some online questions. More importantly, I forgot my questions and can come back for reference.

First, let's talk about the principle of calling the mode dialog box. (That is, you must close this dialog box before you can operate the dialog box in the subsequent window)

In the mode dialog box, use cdicel: onok (), cdialog: oncancel (), and cdialog: onclose () to close the dialog box.

Be sure to pay attention to the previous cdialog: (of course, You can reload this virtual function in your own dialog box. However, you must call the cdialog of the base class later ::)

For details, refer to the simple style to solve the problem.

Cdialog: Close () by default, cdicel: oncancel (), cdialog: oncancel () call cdialog: enddicel (idcancel );

Cdialog: enddialog call cdialog: destroywindows (), cdialog: destroywindows call cdialog: ondestroy ();

Cdialog: onok () First cdialog: updatedata () by default, and then call cdialog: enddialog (idok ).

Cdialog: enddialog call cdialog: destroywindows (), cdialog: destroywindows call cdialog: ondestroy ()

It seems that you probably know the following equation.

Cdialog: Close () = cdialog: oncancel () = cdialog: enddicel (idcancel.

Cdialog: onok () = cdialog: enddialog (idok ).

The difference between cdialog: enddialog (idok) and cdialog: enddicel (idcancel) Is that a cdialog: updatedata (), that is, cdialog: enddialog (idok ), after the close dialog box is closed, the value of the variable associated with the control in the dialog box is updated to the last value entered by the user. However, cdialog: enddicel (idcancel) will not update this value.

I hope you can clearly describe the closing of the mode dialog box.

The following describes the non-modal dialog box.

The Calling principle is:

In the mode-free dialog box, reload your onok (), that is, cmydialog: onok (), and then call cdialog: destroywindows () in the function (). Note: It is not the default cdialog: onok () to close the dialog box.

Reload cmydialog: oncancel (), and then call cdialog: destroywindows () in the function (). Note: The default cdialog: oncancel () is not called to close the dialog box.

It sounds simple, but the following describes a very specific programming problem.

Generally, the non-modal dialog box is global, that is, the new is created on the heap instead of the stack.

In this case, we also need to use Delete to destroy objects, otherwise there will be Memory leakage. When will we delete this object?

On msdn, we can see that the methods provided by Microsoft are,

We need to reload postncdestroy (), that is, we need to implement cmydialog: postncdestroy (), the content is as follows:

Cmydialog: postncdestroy () {cdialog: postncdestroy (); Delete this ;}

In this way, our class will be auto-cleanup.

 

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.