DoModal()函数的功能
帮忙回答一下,好吗?具体点。 问题点数:20、回复次数:4Top
1 楼bigelm(枯燥着快乐着)回复于 2005-06-30 15:12:40 得分 0
CDialog::DoModal
virtual int DoModal( );
Return Value
An int value that specifies the value of the nResult parameter that was passed to the CDialog::EndDialog member function, which is used to close the dialog box. The return value is –1 if the function could not create the dialog box, or IDABORT if some other error occurred.
Remarks
Call this member function to invoke the modal dialog box and return the dialog-box result when done. This member function handles all interaction with the user while the dialog box is active. This is what makes the dialog box modal; that is, the user cannot interact with other windows until the dialog box is closed.
If the user clicks one of the pushbuttons in the dialog box, such as OK or Cancel, a message-handler member function, such as OnOK or OnCancel, is called to attempt to close the dialog box. The default OnOK member function will validate and update the dialog-box data and close the dialog box with result IDOK, and the default OnCancel member function will close the dialog box with result IDCANCEL without validating or updating the dialog-box data. You can override these message-handler functions to alter their behavior.
Note PreTranslateMessage is now called for modal dialog box message processing.
Example
void CTstApp::OnAppAbout()
{
// Construct the dialog box passing the
// ID of the dialog template resource
CDialog aboutDlg(IDD_ABOUTBOX);
// Create and show the dialog box
int nRet = -1;
nRet = aboutDlg.DoModal();
// Handle the return value from DoModal
switch ( nRet )
{
case -1:
AfxMessageBox("Dialog box could not be created!");
break;
case IDABORT:
// Do something
break;
case IDOK:
// Do something
break;
case IDCANCEL:
// Do something
break;
default:
// Do something
break;
};
}
够详细吗?Top
2 楼tans75(品味人生)回复于 2005-06-30 15:21:46 得分 0
怎么全是E文,看不懂呀!Top
3 楼hxue1981(雨山)回复于 2005-06-30 15:21:46 得分 5
顾名思义:DO Modal
让对话框模式生效。主要还是用它来弹出一个对话框!
如CMyDialog dlg;
dlg.DoModal();//弹出CMyDialog类定义的对话框Top
4 楼qrlvls( 空 气 )回复于 2005-06-30 15:31:11 得分 15
DoModal 实际上实现了对话框的创建、显示、关闭的全过程,实际上是一个函数中完成的
而且 DoModal 生成的是一个模态的对话框
DoModal 在一个函数中完成所有这些功能实际上依赖于它所伪造的一个消息循环 RunModalLoop
如果有举的话可以参照 MFC 的源代码Top




