⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 right17-1.htm

📁 Visual C++面向对象程序设计教程(配套习题资源)
💻 HTM
字号:
<html>

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>第 17 章</title>
<base target="rbottom">
<style>
<!--
.右标题   { font-size: 10pt; color: #000080; text-indent: 0; margin: 0 }
.右内容   { font-size: 10pt; text-align: left; text-indent: 0; line-height: 100%; margin: 
               0 }
-->
</style>
</head>

<body>

<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><span style="position: absolute; left: 4; top: -8"><img border="0" src="1.gif" width="63" height="70"></span></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p style="line-height: 100%; text-indent: 0; margin: 0" class="右标题" align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                                                           
&nbsp;&nbsp;&nbsp; <span style="background-color: #CCFF99">第 17 章</span><span style="background-color: #CCFF99">&nbsp;                                                  
</span>&gt;<span style="background-color: #CCFF99"> 第 1 节 </span>&gt;<span style="background-color: #CCFF99">  
 17.1 对话框</span></p>                     
<hr color="#008000" size="1">

<p style="line-height: 100%; text-indent: 0; margin: 0" class="右标题" align="left"> </p>
<p style="line-height: 150%; text-indent: 0; margin: 0" class="右标题" align="left"><font size="2"><font LANG="ZH-CN">在</font>MFC<font LANG="ZH-CN">程序设计中,文档类负责数据的处理,视图类负责数据的显示,而文档类的序列化函数处理数据的存储和读取。为了</font></font><font LANG="ZH-CN" size="2">将数据和数据的显示分开进行处理,因此,需要有两个对象分别实现数据的存储和数据的显示。</font></p>

<p style="line-height: 100%; text-indent: 0; margin: 0" class="右标题" align="left"> </p>

<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">1.    
<font LANG="ZH-CN">文档</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">文档的主要目的是存储数据,文档的操作通过文档类进行,在</font>MFC<font LANG="ZH-CN">中文档类是从类</font>CDocument<font LANG="ZH-CN">中派生出来的类。</font></font></p>
<p ALIGN="justify" style="line-height: 200%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">(1)    
CDocument类</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">&nbsp;&nbsp;   
CDocument<font LANG="ZH-CN">用于:</font></font></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
创建文档对象。</font>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
将数据中的任何更改通知给使用此类的所有视图。</font>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
创建、写入和读出磁盘上的文件。&nbsp;</font>
<p ALIGN="justify" style="line-height: 200%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">(2)    
CDocument类中使用的函数</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UpdateAllViews (CView* pSender, LPARAM lHint = 0L,CObject* pHint = NULL);</font></p>   
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font LANG="ZH-CN" size="2">&nbsp;&nbsp;&nbsp;    
该函数用于通知视图在文档中的数据已发生更改这一消息。</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">2.    
<font LANG="ZH-CN">视图</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">视图的主要目的是负责保存在文档中数据的实际显示,视图的操作通过视图类进行,在</font>MFC<font LANG="ZH-CN">中视图类是从类</font>CView<font LANG="ZH-CN">中派生类出来的类。</font></font></p>
<p ALIGN="justify" style="line-height: 200%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">(1)    
CView类&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
<img border="0" src="right12.gif" style="float: right" width="316" height="179"></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CView<font LANG="ZH-CN">类是所有视图类的基类,不能直接使用,但必须有一个类由其派生。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CView<font LANG="ZH-CN">类的主要数据成员和成员函数有:</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2" color="#008000"><font LANG="ZH-CN">&nbsp;&nbsp;   
① </font>OnDraw( )<font LANG="ZH-CN">:保存所有显示代码。</font></font></p>   
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2" color="#008000"><font LANG="ZH-CN">&nbsp;&nbsp;   
② </font>m_pDocument<font LANG="ZH-CN">:保存指向相关文档的指针。</font></font></p>   
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2" color="#008000"><font LANG="ZH-CN">&nbsp;&nbsp;   
③ </font>GetDocument( )<font LANG="ZH-CN">:返回指向与视图相关的文档的指针。</font></font></p>   
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2" color="#008000"><font LANG="ZH-CN">&nbsp;&nbsp; 
④ </font>OnUpdate( )<font LANG="ZH-CN">:当调用相关文档类的</font>UpdateAllViews(    
)<font LANG="ZH-CN">函数时,该函数将被调用。</font></font></p>
<p ALIGN="justify" style="line-height: 200%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">(2)    
CEditView类</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CEditView<font LANG="ZH-CN">类主要被设计用来支持类似编辑控件所要实现的功能,常见的文本操作基本上都是由该类支持实现的。值得注意的是,</font>CEditView<font LANG="ZH-CN">类是从</font>CCtrlView    
<font LANG="ZH-CN">类派生,而不是</font>Cview<font LANG="ZH-CN">类。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CEditView<font LANG="ZH-CN">类的主要成员函数有:</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2" color="#008000"><font LANG="ZH-CN">&nbsp;&nbsp;&nbsp;① </font>FindText( )<font LANG="ZH-CN">:调用此函数搜索</font>CEditView<font LANG="ZH-CN">对象的文本缓冲区。</font></font></p>   
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2" color="#008000"><font LANG="ZH-CN">&nbsp;&nbsp;&nbsp;② </font>OnReplaceSel( )<font LANG="ZH-CN">:当用户在标准替换对话框中选择了“替换”按钮时,此函数将被</font>CEditView<font LANG="ZH-CN">调用。</font></font></p>   
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2" color="#008000"><font LANG="ZH-CN">&nbsp;&nbsp;&nbsp;③ </font>OnTextNotFound( )<font LANG="ZH-CN">:此函数在查找操作没有找到任何匹配文本时调用。</font></font></p>   
<p ALIGN="justify" style="line-height: 200%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">(3)    
CFormView类</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CFormView<font LANG="ZH-CN">类从</font>CScrollView    
<font LANG="ZH-CN">类派生,提供滚动功能,可以将一屏无法显示的数据利用滚动条拖动显示,有助于在应用程序中合并窗体。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">3.    
<font LANG="ZH-CN">文档模板</font></font><img border="0" src="right11.gif" style="float: right" width="184" height="80"></p>
<p ALIGN="JUSTIFY" style="line-height: 200%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">(1)    
CDocTemplate类</font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">文档模板类(</font>CDocTemplate<font LANG="ZH-CN">)是从类</font>CCmdTarget<font LANG="ZH-CN">派生的,它在</font>MFC<font LANG="ZH-CN">类库中的层次位置如图所示。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 200%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">(2)    
CDocTemplate类的主要成员函数</font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2" color="#008000"><font LANG="ZH-CN">&nbsp;&nbsp;   
①</font> 
LoadTemplate( )<font LANG="ZH-CN">:加载指定的模板。</font></font></p>   
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2" color="#008000"><font LANG="ZH-CN">&nbsp;&nbsp;   
②</font> 
AddDocument( )<font LANG="ZH-CN">:给文档模板添加指定的文档。</font></font></p>   
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2" color="#008000"><font LANG="ZH-CN">&nbsp;&nbsp;   
③</font> 
RemoveDocument( )<font LANG="ZH-CN">:从文档模板列表中删除文档。</font></font></p>   
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2" color="#008000"><font LANG="ZH-CN">&nbsp;&nbsp;   
④</font> 
GetFirstDocPosition( )<font LANG="ZH-CN">:获得与文档模板相关的第一个文档的位置。</font></font></p>   
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2" color="#008000"><font LANG="ZH-CN">&nbsp;&nbsp;   
⑤</font> 
GetNextDoc( )<font LANG="ZH-CN">:获得文档及下一个文档。</font></font></p>   
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2" color="#008000"><font LANG="ZH-CN">&nbsp;&nbsp;   
⑥</font> 
CreateNewDocument( )<font LANG="ZH-CN">:建立文档。</font></font></p>   
<p ALIGN="JUSTIFY" style="line-height: 200%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">(3)    
文档模板CDocTemplate类的功能</font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">在</font>Visual    
C++<font LANG="ZH-CN">中,文档类、与文档类相关联的视图类以及为视图类提供显示的框架窗口都是由文档模板创建的。每一种文档类型都有一种文档模板与之相对应,文档模板负责创建和管理该文档类型的所有文档。文档、框架窗口和视图的创建过程之间的先后顺序为:创建文档→创建框架窗口→创建视图。</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font LANG="ZH-CN" size="2">文档、视图和框架三者之间是相互关联、相互协调的,彼此都包含了指向对方的指针。它们之间的联系是通过文档模板的构造函数来实现的。</font></p>
<p style="line-height: 100%; text-indent: 0; margin: 0" align="left"> </p>

<hr size="1" color="#008000">
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>            

<p style="line-height: 100%; margin-top: 0; margin-bottom: 0">&nbsp;&nbsp; <span style="position: absolute; left: 34; top: 1137"><a href="right16-3.htm" target="_self"><img border="0" src="rightd1.gif" width="113" height="70"></a></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="position: absolute; left: 503; top: 1142"><a href="right17-2.htm" target="_self"><img border="0" src="rightd2.gif" width="124" height="63"></a></span></p>                     

</body>

</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -