Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use oncancel

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report