The OnClose and OnCancel of MFC

Source: Internet
Author: User

In a dialog box where. Pressing the ESC key with the Red fork above will call the OnCancel () function by default.

Now I'm going to pop a dialog box instead of closing the program after pressing the ESC keyboard, but this time click on the Red Fork

The program will not close, in order to resolve the problem. We're going to reload the OnClose function,

void Cmy1223dlg::oncancel () {MessageBox ("Suppose it's strange", "hint", MB_OK);//cdialog::oncancel ();} void Cmy1223dlg::onclose () {//Todo:add your message handler code here and/or call Defaultcdialog::onclose ();}


This is called after. Click on the Red Fork, but found also will pop up this dialog box:

Because OnClose () defaults to the IDCANCEL message, OnClose () enters the Cmy1223dlg::oncancel () function;

void Cmy1223dlg::oncancel () {MessageBox ("Suppose it's strange", "hint", MB_OK);//cdialog::oncancel ();} void Cmy1223dlg::onclose () {//Todo:add your message handler code here and/or call Defaultcdialog::oncancel ();//cdialog:: OnClose ();}

So to OnClose close the OnCancel (cmy1223::oncancel) function that does not enter the derived class, the OnCancel (Cdialog::oncancel) of the parent class is called directly inside the OnClose function;

Cdialog::oncancel (); Call EndDialog (IDCANCEL) inside, so you can call EndDialog directly (IDCANCEL)

As to why the OnClose function goes into the OnCancel function. I think very strange practice, the reason is unclear, the Internet to find a very much also did not say clearly!


The OnClose and OnCancel of MFC

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.