?? teach_road_31.htm
字號:
<html><head><meta http-equiv="Content-Type"content="text/html; charset=gb_2312-80"><title>VC Road</title><style type="text/css" MEDIA="screen"><!--a {text-decoration: underline;}a:hover {color:red; text-decoration:underline}small {color: navy; font-size: 12px ; line-height:16px;}h1 {color: navy; font-size: 12px ; line-height:16px;}
big {color: navy; font-size: 22px ; line-height:26px;}
td {color: navy; font-size: 12px ; line-height:16px;bgcolor="#FFCFA3";}--></style></head>
<body background="../img/ground.gif">
<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" target=_blank><img border="0"
src="http://www.0828.com/pay/code.gif" width="468" height="15"></a><br><small>你每點一下上面的廣告我就能有更多的上網時間為大家尋找資料</small></font>
</p>
<p align=center><big>3.1 文檔 視圖 框架窗口間的關系和消息傳送規律</big></p>
<table border=0 align=center width=80%>
<tr><td>
<p>在MFC中M$引入了文檔-視結構的概念,文檔相當于數據容器,視相當于查看數據的窗口或是和數據發生交互的窗口。(這一結構在MFC中的OLE,ODBC開發時又得到更多的拓展)因此一個完整的應用一般由四個類組成:CWinApp應用類,CFrameWnd窗口框架類,CDocument文檔類,CView視類。(VC6中支持創建不帶文檔-視的應用)</p>
<p>在程序運行時CWinApp將創建一個CFrameWnd框架窗口實例,而框架窗口將創建文檔模板,然后有文檔模板創建文檔實例和視實例,并將兩者關聯。一般來講我們只需對文檔和視進行操作,框架的各種行為已經被MFC安排好了而不需人為干預,這也是M$設計文檔-視結構的本意,讓我們將注意力放在完成任務上而從界面編寫中解放出來。</p>
<p>在應用中一個視對應一個文檔,但一個文檔可以包含多個視。一個應用中只用一個框架窗口,對多文檔界面來講可能有多個MDI子窗口。每一個視都是一個子窗口,在單文檔界面中父窗口即是框架窗口,在多文檔界面中父窗口為MDI子窗口。一個多文檔應用中可以包含多個文檔模板,一個模板定義了一個文檔和一個或多個視之間的對應關系。同一個文檔可以屬于多個模板,但一個模板中只允許定義一個文檔。同樣一個視也可以屬于多個文檔模板。(不知道我說清楚沒有)</p>
<p>接下來看看如何在程序中得到各種對象的指針:<ul>
<li>全局函數AfxGetApp可以得到CWinApp應用類指針</li>
<li>AfxGetApp()->m_pMainWnd為框架窗口指針</li>
<li>在框架窗口中:CFrameWnd::GetActiveDocument得到當前活動文檔指針</li>
<li>在框架窗口中:CFrameWnd::GetActiveView得到當前活動視指針</li>
<li>在視中:CView::GetDocument得到對應的文檔指針</li>
<li>在文檔中:CDocument::GetFirstViewPosition,CDocument::GetNextView用來遍歷所有和文檔關聯的視。</li>
<li>在文檔中:CDocument::GetDocTemplate得到文檔模板指針</li>
<li>在多文檔界面中:CMDIFrameWnd::MDIGetActive得到當前活動的MDI子窗口</li>
</ul>
</p>
<p>一般來講用戶輸入消息(如菜單選擇,鼠標,鍵盤等)會先發往視,如果視未處理則會發往框架窗口。所以定義消息映射時定義在視中就可以了,如果一個應用同時擁有多個視而當前活動視沒有對消息進行處理則消息會發往框架窗口。</p>
<p></p>
<p></p>
<p></p>
<p></p>
<p align=center><a href=teach_first.htm#charpter3>返回</a></p>
</td></tr>
</table>
<p align=center><small>版權所有 聞怡洋 <a href=http://vchelp.163.net/>http://vchelp.163.net/</a></small></p>
<!-- 耐特付費廣告代碼開始 不得修改. -->
<center><script language="javascript">
<!--
var date = new Date();
var ra = date.getTime() % 1000;
var ua = document.URL;
document.write("<iframe src='http://www.china-free.com/cgi-bin/ad/random.cgi?id=560' width=468 height=60 scrolling=no marginwidth=0 marginheight=0 frameborder=0 vspace=0 hspace=0 >");
document.write("<a href='http://www.china-free.com/cgi-bin/ad/random.cgi?id=560' target='_blank'>");
document.write("<img src='http://www.china-free.com/cgi-bin/ad/random.cgi?job=go&id=560' width=468 height=60 border=0></a>");
document.write("</iframe>");
//-->
</script>
<noscript>
<a target="_blank" href="http://www.china-free.com/cgi-bin/ad/random.cgi?id=560">
<img src="http://www.china-free.com/cgi-bin/ad/random.cgi?job=go&id=560" width="468" height="60" border="0"></a>
</noscript>
<br><a HREF="http://www.china-free.com/ad" target="_blank"><img SRC="http://www.china-free.com/ad/bd.gif" BORDER="0" ></a></center>
<!-- 耐特付費廣告代碼結尾. -->
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -