Create mode dialog box

Source: Internet
Author: User

 

When a modal dialog box is used, the call function will not return immediately after the dialog box pops up, but will not return after the dialog box is destroyed (note that the messages in other windows will still be transmitted after the dialog box pops up ). Therefore, user input cannot be received in other windows when the dialog box is used. To create a mode dialog box, callCDialog: DoModal (). The following code demonstrates this usage:

CYourView: OnOpenDlg ()
  
{
  
CYourDlg dlg;
  
Int iRet = dlg. DoModal ();
  
}
  

CDialog: the return value of DoModal () is IDOK and IDCANCEL. Indicates that the operator selects "OK" or "cancel" in the dialog box ". Since DoModal does not return a result before the dialog box is destroyed, you can use local variables to reference objects. After exiting the function body, the object will also be destroyed. The modeless dialog box cannot be used in this way. The create modeless dialog box in section 5.3 will be described in detail.

You needThe return value of DoModal () determines your next action, and obtaining the return value is also a big reason for using a mode dialog box.

Pay attention to some issues when using the stateful dialog box. For example, do not generate a modal dialog box during repeated event processing. For example, a pattern dialog box is generated in the timer, because the previous dialog box has not exited yet, the timer message will pop up in the next dialog box.

Similarly, in your dialog box class, different values can be called to return to the caller.CDialog: OnOK () or CDialog: OnCancel () to return IDOK or IDCANCEL. If you want to return other values, you need to call
CDialog: EndDialog (int nResult); where nResult serves as the return value of the DoModal () call.

The following code demonstrates how to use your function to exit the dialog box:

Void CMy52_s1View: OnLButtonDown (UINT nFlags, CPoint point)
  
{// Create a dialog box and get the returned value
  
CView: OnLButtonDown (nFlags, point );
  
CTestDlg dlg;
  
Int iRet = dlg. DoModal ();
  
CString szOut;
  
SzOut. Format ("return value % d", iRet );
  
AfxMessageBox (szOut );
  
}
  
// Reload OnOK and OnCancel
  
Void CTestDlg: OnOK ()
  
{// Do nothing
  
}
  
Void CTestDlg: OnCancel ()
  
{// Do nothing
  
}
  
// Map the three button messages in the dialog box
  
Void CTestDlg: OnExit1 ()
  
{
  
Related Article

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.