📄 01_9_17_7.asp.html
字号:
<html><head><meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<TITLE>计算机世界网-2.3.3类CMyView与CMyDoc</TITLE></HEAD>
<style>
.a14{font-size:14px;text-indent:25px;line-height:20px}
.f{font-size:18px;color=#0f3ccd}
img{border:0px;}
td,p,input{font-fammily:verdana,宋体;font-size:12px;}
A:link {text-decoration:none;color:black}
A:visited {text-decoration:none;color:#80006f}
A:hover {text-decoration:underline;color:black}
</style>
<center>
<BODY topmargin=2 leftmargin=0>
<style>
.v12{font-size:10pt;color:"#ffffff";FONT-WEIGHT: bold}
.v14{font-size:14px;text-indent:25px;line-height:20px}
img{border:0px;}
td,p,input,select{font-fammily:verdana,宋体;font-size:12px;}
A:link {text-decoration:none;color:black}
A:visited {text-decoration:none;color:#80006f}
A:hover {text-decoration:underline;color:black}
</style>
<style>
.v13{font-size:10pt;color:"#ffffff";FONT-WEIGHT: bold}
.v12{font-size:13px;color:"#4C029C";FONT-WEIGHT: bold}
.v14{font-size:14px;text-indent:25px;line-height:20px}
img{border:0px;}
td,p,input,select{font-fammily:verdana,宋体;font-size:12px;}
A:link {text-decoration:none;color:black}
A:visited {text-decoration:none;color:#80006f}
A:hover {text-decoration:underline;color:black}
</style>
<!--头-->
<table align=center cellpadding="0" cellspacing="0" border="0" width="767">
<tr><td valign=bottom>
<table cellpadding="0" cellspacing="0" border=0>
<tr><td valign=top><img src="../../../../../center/image/ccwlogo.gif"></td></tr>
<tr><td height="27" valign=top><img src="../../../../../center/image/knowledge.gif" width="207" height="27"></td></tr>
</table></td>
<td valign=bottom width=556 bgcolor="#4c029c" height=96>
<table cellpadding="0" cellspacing="0" border=0 width=556 bgcolor="#4c029c" height=96>
<tr><td height=25 valign=bottom bgcolor="#ffffff" colspan=2 ><img src="../../../../../image2002/top.gif" usemap="#F"></td></tr>
<tr valign=middle >
<td align=center valign=middle height="60" align=center>
<!-- <a href="http://www.ccw.com.cn/search/" target=_blank><img src="../../../../../img2/esearch.GIF" border=0 width=468 height=60></a> --><a href="http://www.ccw.com.cn/html/search/thememail/" target=_blank><img src="../../../../../img2/topbanner_thememail.GIF" border=0 width=468 height=60></a>
</td>
<td align=center width=15%>
<table width=95%>
<tr><td><a href="mailto:center@ccw.com.cn?subject=我要投稿:" target=_blank><font class=v13>我要投稿</a><br><a href="mailto:center@ccw.com.cn?subject=编读往来"><font class=v13>编读往来</a><br><a href="javascript:AddBookMark('计算机世界网首页')"><font class=v13>加入收藏</a></font></td></tr>
</table>
</td>
</tr>
<tr><td bgcolor="#ffffff" height=1 colspan=2 ></td></tr>
<tr><td bgcolor="#b4aafc" height=2 colspan=2 ></td></tr></table>
<map name="F">
<area href="http://www.ccw.com.cn/" shape="rect" coords="29, 3, 61, 18" target=_blank>
<area href="http://www.ccw.com.cn/news1/" shape="rect" coords="72, 3, 143, 18" target=_blank>
<area href="http://www.ccw.com.cn/center/" shape="rect" coords="155, 2, 216, 18" target=_blank>
<area href="http://www.ccw.com.cn/work/" shape="rect" coords="225, 2, 299, 18" target=_blank>
<area href="http://www.ccw.com.cn/search/" shape="rect" coords="310, 3, 364, 19" target=_blank>
<area href="http://www3.ccw.com.cn/" shape="rect" coords="372, 2, 412, 19" target=_blank>
<area href="http://www2.ccw.com.cn/" shape="rect" coords="424, 2, 550, 18" target=_blank></map>
</td></tr>
<tr><td colspan=2 bgcolor="#b4aafc">
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr>
<td width=26% align=center><font class=v12>【2003年6月24日】 </font></td>
<td CLASS=V12> <a href="http://www.ccw.com.cn/center/topic.asp">专 题</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/tech.asp">技 术</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/prod.asp">产 品</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/app.asp">应 用</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/net.asp">网 络</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/prog.asp">编 程</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/skill.asp">技 巧</a> </td>
</tr>
</table>
</td></tr>
</table>
<table align=center width=728>
<tr><td align=center><br><h2><font color='#0f3ccd'>2.3.3类CMyView与CMyDoc</font></h2>
</td></tr><tr><td align=right>01-9-17 上午 09:59:29<br><hr size=1 width=718 color=#f46240></td></tr></table><br>
<table align=center width=728><tr><td valign=top width=600>
<table width=100% ><tr><td class=a14>之所以把CMyView类和CMyDoc类一起介绍是因为这两个类是密切相关的,</td></tr></table>
<table width=100% >
<tr>
<td class=a14> 下面的框图可以说明文档与视窗的关系。</td>
</tr>
<tr>
<td class=a14>
<div align="center"><img src="01_9_17_5.GIF" width="346" height="170"></div>
</td>
</tr>
</table>
<table width=100% ><tr><td class=a14>
在这个框图当中,文档是由文档模板对象生成的,并由应用程序对象管理,而用户则是通过与文档相联系的视窗对象来存储、管理应用程序的数据,用户与文档之间的交互则是通过与文档相关联的视窗对象来进行的。</td></tr></table><table width=100% ><tr><td class=a14>
生成一个新的文档的时候,MFC程序同时生成一个框架窗口,并且在框架窗口的客户区中生成一个视窗对象作为框架窗口的子窗口,这个子窗口以可视化的方式表现文档中的内容。视窗的重要功能就是负责处理用户的鼠标、键盘等操作,通过对视窗对象的处理达到处理文档对象的目的。</td></tr></table><table width=100% ><tr><td class=a14>
要指出的一点是,WINDOWS应用程序分单文档界面SDI和多文档界面MDI两种,在单文档界面中,文档窗口与主框架窗口是同一概念。而这时的视窗对象则是显示在文档窗口的客户区当中。我们先前生成的TEST程序使用的就是单文档界面方式,此时文档窗口是主框架窗口,即类CMAINFRAME的对象。</td></tr></table><table width=100% ><tr><td class=a14>
下面将以一个例子来说明这两个类之间的关系。</td></tr></table><table width=100% ><tr><td class=a14>
前面已经提到,文档类是用来存放程序中的数据的,所以我们首先在文档类CMyDoc中加入一个成员变量用来存放数据。</td></tr></table><table width=100% ><tr><td class=a14>
在左边的工作区用右键单击CMyDoc选项,在弹出的菜单中选中Add member variable菜单项。</td></tr></table><table width=100% ><tr>
<td class=a14>
<div align="center"><img src="01_9_17_6.GIF" width="432" height="324"><br>
<br>
</div>
<div align="center">图2.2</div>
</td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
系统弹出Add Member Variable对话框。Variable Type一栏用来输入成员变量的类型。这里设置为CString,即字符串类型,Variable Declaration一栏用来输入变量的名字,这里不妨输入为mystring,Access组合框用来设置成员变量的访问权限,缺省为Public,设好后单击OK按钮关闭对话框。如下图2.3所示:</td></tr></table><table width=100% ><tr>
<td class=a14>
<div align="center"><img src="01_9_17_7.GIF" width="402" height="172"><br>
<br>
图2.3</div>
</td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
这时,如果打开类CMyDoc的头文件、可以发现其中已经自动加入了我们定义的公有变量mystring。这个变量就可以作为我们的文档类的数据存储空间,因为mystring是公有成员,它就可以被文档对应的视窗所处理了。</td></tr></table><table width=100% ><tr><td class=a14>
在VIEW菜单中选择ClassWizard菜单项,系统打开MFC ClassWizard对话框,接下来我们要为视窗类添加处理键盘事件的成员函数。在Classname一栏中选中类CMyView,然后在messages一栏中选中消息wm_char,单击add function按钮,系统就自动往CMyView类中添加了处理wm_char消息的成员函数的框架。单击edit code按钮,接下来对OnChar这个成员函数进行编辑和修改。</td></tr></table><table width=100% ><tr><td class=a14>
可以看出系统已经自动在这个成员函数中添加了CMyView的基类CView的WM_CHAR消息的处理函数。注意这一行代码:</td></tr></table><table width=100% ><tr><td class=a14>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -