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