📄 index031.htm
字号:
<html>
<style type="text/css"><!--
.p9 { font-family: "宋体"; font-size: 9pt}a {text-transform: none; text-decoration: none;}
a:hover {text-decoration: underline; color: #FF0000;}
--></style>
<body background="../../../backg.jpg">
<h3 align="center"><font COLOR="#AOAO99"></font></h3>
<table width="100%" border="1" cellspacing="1">
<tr><td><p align="center"><font color="#FF0000">如何创建和使用无模式对话框</font></td></tr>
<tr><td><p>
</Br>
MFC将模式和无模式对话封装在同一个类中,但是使用无模式对话需要几个对话需要几个额处的步骤。首先,使用资源编辑器建立对话资源并使用ClassWizard创建一个CDialog的派生类。模式和无模式对话的中止是不一样的:模式对话通过调用CDialog : : EndDialog 来中止,无模式对话则是调用CWnd: : DestroyWindow来中止的,函数CDialog : : OnOK和CDialog : : OnCancel调用EndDialog ,所以需要调用DestroyWindow并重置无模式对话的函数。<Br>
void CSampleDialog : : OnOK ( )<Br>
{<Br>
// Retrieve and validate dialog data .<Br>
if (! UpdateData (TRUE) )<Br>
{<Br>
// the UpdateData rountine<Br>
will set focus to correct item TRACEO (" UpdateData failed during dialog termination .\n")<Br>
return<Br>
}<Br>
</Br>
//Call DestroyWindow instead of EndDialog .<Br>
DestroyWindow ( )<Br>
}<Br>
</Br>
void CSampleDialog : : OnCancel ( )<Br>
{<Br>
//Call DestroyWindow instead of EndDialog .<Br>
DestroyWindow ( )<Br>
}<Br>
</Br>
其次,需要正确删除表示对话的C++对象。对于模式对来说,这很容易,需要创建函数返回后即可删除C++对象;无模式对话不是同步的,创建函数调用后立即返回,因而用户不知道何时删除C++对象。撤销窗口时工作框调用CWnd : : PostNcDestroy,可以重置该函数并执行清除操作,诸如删除this指针。<Br>
void CSampleDialog : : PostNcDestroy ( )<Br>
{<Br>
// Declete the C++ object that represents this dialog.<Br>
delete this<Br>
</Br>
最后,要创建无模式对话。可以调用CDialog : : DoModal创建一个模式对放,要创建一个无模式对话则要调用CDialog: : Create。下面的例子说明 了应用程序是如何创建无模式对话的: 象;无模式对话不是同步的,创建函数调用后立即返回,<Br>
void CMainFrame : : OnSampleDialog ( )<Br>
{<Br>
//Allocate a modeless dialog object .<Br>
CSampleDilog * pDialog =new CSampleDialog<Br>
ASSERT_VALID (pDialog) Destroy ( )<Br>
</Br>
//Create the modeless dialog . represents this dialog.<Br>
BOOL bResult = pDialog —> Creste (IDD_IDALOG)<Br>
ASSERT (bResult )<Br>
}<Br>
</Br>
</p></td></tr>
</table><p align="center"><img src="../../../logo.gif" align="center"><center><table><tr><td><a href="http://www.ourcode.net" target=_top>www.OurCode.net</a><Br>版权所有: 2002-2008</a></td></tr></table></center></p>
</body><SCRIPT LANGUAGE='JavaScript' SRC='../../../navigate_bar.js'></SCRIPT><SCRIPT LANGUAGE='JavaScript'>write_tail();</SCRIPT></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -