How to use oncancel
Editor to share with you how to use oncancel, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!
OnCancel, a computer term for calling forms.
Introduction to OnCancel entry
CDialog::OnCancel
VirtualvoidOnCancel ()
Description:
The form calls this member function when the user clicks the Cancel button or presses the ESC key in a modal or modeless dialog box.
Override the member function and execute the Cancel button action. The default is to call EndDialog to simply abort the modal dialog box and make DoModal return IDCANCEL.
If you implement the Cancel button in a modeless dialog box, you must override the OnCancel member function and call DestoryWindow in it. Cannot call the base class member function, which will call EndDialog, making the dialog box invisible although it exists.
Similarities and differences between OnOK () and OnCancel ()
First of all, OnOK is the response to ID_OK, and OnCancel is the response to IDCANCEL. The former corresponds to the Enter of the keyboard and the latter corresponds to Esc.
MFC:
1. CalledwhentheuserclickstheOKbutton (thebuttonwithanIDofIDOK)
2 、 TheframeworkcallsthismemberfunctionwhentheuserclickstheCancelbuttonorpressestheESCkeyinamodalormodelessdialogbox.
Both functions are member functions of virtual of the CDialog class, that is, MFC wants you to overload them. One thing the two functions have in common is that they both call CDialog::EndDialog. The CDialog::EndDialog function is called in CDialog::OnOK ();. The role of EndDialog is as follows, extracted from MSDN:
Callthismethodtodestroyamodaldialogbox
Donotcall EndDialog todestroyamodelessdialogbox.CallCWindow::DestroyWindowinstead
Modal dialogs can be destroyed with EndDialog and modeless dialogs with DestroyWindow. The following excerpt is from MSDN: Ifyouimplementthe OK buttoninamodelessdialogbox,youmustoverridethe OnOK methodandcallDestroyWindowinsideit.Donotcallthebase-classmethod,becauseitcallsEndDialogwhichmakesthedialogboxinvisiblebutdoesnotdestroyit.
The above is all the contents of the article "how to use oncancel". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!