The OnClose and OnCancel of MFC

Source: Internet
Author: User

In a dialog box, press the ESC key and the Red fork above, the default is to call the OnCancel () function;

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

program does not close, in order to solve this problem, we will overload the OnClose function,

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


After this call, click on the Red Fork, but found also will pop up this dialog box:

Because OnClose () enters the IDCANCEL message by default, OnClose () enters the Cmy1223dlg::oncancel () function;

void Cmy1223dlg::oncancel () {MessageBox ("If it comes out really 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 to enter the OnCancel function, I think it is very strange practice, the reason is unclear, on the internet to find a lot of 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.