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 ()
{