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