?? teach_road_58.htm
字號:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb_2312-80">
<meta name="GENERATOR" content="聞怡洋 wyy_cq@21cn.com">
<title>Visual C++/MFC開發(fā)指南</title>
<SCRIPT LANGUAGE='JavaScript' SRC='../../submit_navigate_bar.js'></SCRIPT>
<link REL="stylesheet" HREF="../../main.css">
</head>
<SCRIPT LANGUAGE='JavaScript'>write_body();</SCRIPT>
<SCRIPT LANGUAGE='JavaScript'>write_bar();</SCRIPT>
<p align="center"><a
HREF="http://www.0828.com/pay/cgi-bin/random.cgi?job=go&id=820"
target="_blank">
<img SRC="http://www.0828.com/pay/cgi-bin/random.cgi?id=820" BORDER="0"
width="468" height="60"></a><br>
<font size="2"><a href="http://www.0828.com/pay/index.html"><img border="0"
src="http://www.0828.com/pay/code.gif" width="468" height="15"></a><br>
<small>你每點(diǎn)一下上面的廣告我就能有更多的上網(wǎng)時(shí)間為大家尋找資料</small></font>
</p>
<table width=98% cellspacing="0" cellpadding="0" align=center><!--整體框架-->
<tr><td>
<table border=0 width="100%" cellspacing="0" cellpadding="2"><!--標(biāo)記放置區(qū)域-->
<tr>
<td width="30%" align="center" bgcolor="#003D84" valign=middle><img src=../../img/brand_200_60.gif width=200 height=60 alt="LOGO1"></td>
<td width="70%" align="center" bgcolor="#003D84" valign=middle><img src=../../img/logo_400_60.gif width=400 height=60 alt="LOGO2"></td>
</tr>
<tr>
<td colspan="2" bgcolor="#0080C0" align=center><font color=white>您當(dāng)前位置</font></font> <a href=../../index.htm><font color=white>首頁</font></a> <a href=../index.htm><font color=white>開發(fā)教程</font></a> <a href=index.htm><font color=white><font class=engul>Visual C++/MFC</font>入門教程</font></a> <font color=white>5.8 建立以對話框?yàn)榛A(chǔ)的應(yīng)用</font><SCRIPT LANGUAGE='JavaScript'>write_command();</SCRIPT></td>
</tr>
</table><!--標(biāo)記放置區(qū)域 END-->
<table border=0 width=100% cellspacing="0" cellpadding="0">
<tr>
<td><!--begin-->
<br>
<p align=center><big>5.8 建立以對話框?yàn)榛A(chǔ)的應(yīng)用</big></p>
<table border=0 align=center width=100%>
<tr><td>
<small>
<p>我認(rèn)為初學(xué)者使用以對話框?yàn)榛A(chǔ)的應(yīng)用是一個(gè)比較好的選擇,因?yàn)檫@樣一來可以擺脫一些開發(fā)界面的麻煩,此外也可以利用ClassWizard自動的添加消息映射。</p>
<p>在VC中提供了生成“以對話框?yàn)榛A(chǔ)的應(yīng)用”的功能,你所需要選擇的是在使用AppWizard的第一步選擇“對話框?yàn)榛A(chǔ)的應(yīng)用”,<a href=58_g1.gif target=_blank>如圖</a>。VC會生成包含有應(yīng)用派生類和對話框派生類的代碼。在應(yīng)用類的InitInstance()成員函數(shù)中可以看到如下的代碼:<pre>
BOOL CMy58_s1App::InitInstance()
{
CMy58_s1Dlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
return FALSE;
}
</pre>
這是產(chǎn)生一個(gè)有模式對話框并創(chuàng)建它,在對話框返回后通過返回FALSE來直接退出。在設(shè)計(jì)時(shí)通過編輯對話框資源你可以設(shè)計(jì)好界面,然后通過ClassWizard映射消息來處理客戶的輸入,由于前幾節(jié)已經(jīng)講過本節(jié)也就不再重復(fù)。</p>
<p>同樣基于對話框的應(yīng)用也同樣可以使用屬性對話框做為界面,或者是通過使用經(jīng)過派生的通用對話框作為界面。</p>
<p><b>提示</b>:當(dāng)你使用有模式對話框時(shí)最開始是無法隱藏窗口的,而只能在對話框顯示后再隱藏窗口,所以這會造成屏幕的閃爍。一個(gè)解決辦法就是采用無模式的對話框,無模式的對話框在創(chuàng)建后是隱藏的,直到你調(diào)用ShowWindow(SW_SHOW)才會顯示。相關(guān)代碼如下:
<pre>
BOOL CMy58_s1App::InitInstance()
{
//必須新生成一個(gè)對象,而不能使用局部變量
CMy58_s1Dlg* pdlg=new CMy58_s1Dlg;
m_pMainWnd = pdlg;
pdlg->Create();
return TRUE;
}
</pre>
</p>
</small>
</td>
</tr>
<tr><td>
<small>
<p align=center><a href=index.htm#charpter5>返回</a></p>
</small>
</td></tr>
</table>
<p align=center><small>版權(quán)所有 聞怡洋 <a href=http://www.vchelp.net/>http://www.vchelp.net/</a></small></p>
</td><!--end-->
</tr>
</table>
</td></tr></table><!--整體框架 END-->
<SCRIPT LANGUAGE='JavaScript'>write_tail();</SCRIPT>
</body></html>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -