?? 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="../di2001.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>
</body></html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -