mfc--dialog box (ii), modal dialog box

Source: Internet
Author: User

The Windows dialog is divided into two categories: modal dialogs and non-modal dialog boxes.

Module dialog box, when it pops up, the other windows of the application will no longer accept user input, only after the corresponding user input of the dialog box, after the corresponding action to exit, other windows can continue to interact with the user.

Non-modal dialog box, it pops up, the other windows of the program can still be input to the corresponding user.

modal dialog box

First, let's figure out how the main interface is displayed.

Join this solution named addition, when you create a new MFC project, a ADDITIONDLG. cpp file appears with a InitInstance () function that is used to complete the initialization work.

Cadditiondlg Dlg;//defining a dialog Class Cadditiondlg object Dlgm_pMainWnd = &dlg;//set Dlg as the main windowINT_PTR Nresponse = dlg. DoModal ();//The dialog box appears dlg and assigns the return value of the DoModal function to Nresponseif(Nresponse = = IDOK)//determines whether the return value is an OK button{       //Todo:place code here-handle when the dialog is//dismissed with OK}   Else if(Nresponse = = IDCANCEL)//determine if the return value is a Cancel button{       //Todo:place code here-handle when the dialog is//dismissed with Cancel}

As can be seen from the above code, first define a dialog class object, and then assign its first address to m_pMainWnd, that is, set the main window

Then is the popup dialog box, pop-up dialog is a key function, is the dialog box class DoModal () function

CDialog: The prototype of the:D Omodal () function is: Virtual INT_PTR DoModal ();

Return value: An integer value that specifies the value of the Nresult parameter passed to Cdialog::enddialog, which is used to close the dialog box. Returns 1 if the function cannot create a dialog box, or returns Idabort if there are other errors.

Therefore, by judging the return value of the DoModal () function, it is determined that the press is holding a button,

For example, if you press the OK button (the OK button's message handler function OnBnClickedOK () is the Cdialogex::onok () function),

1 void Ctipdlg::onbnclickedok () 2 {3     // TODO: Add control notification handler code here 4     Cdialogex::onok (); 5 }

And the return value of the Cdialogex::onok () function is Idok

As for the OK Button message processing function name OnBnClickedOK source, can refer to, at a glance,

Similarly, if the Cancel button, there will also be

1 void Ctipdlg::onbnclickedcancel () 2 {3     // TODO: Add control notification handler code here 4     cdialogex::oncancel (); 5 }

mfc--dialog box (ii), modal dialog box

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.