📄 105153.html
字号:
<html><head><title>ActiveDocument结构概述</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="Keywords" content="ActiveDocument结构概述">
<meta name="description" content="ActiveDocument结构概述">
<style type="text/css">
<!--
.style2 {font-size: 14px}
-->
</style>
<link href="105153_files/Skin1.css" rel="stylesheet" type="text/css"></head><body leftmargin="0" topmargin="0">
<table class="top_Channel" style="" align="center" border="0" cellpadding="0" cellspacing="0" width="760">
<tbody><tr>
<td colspan="2" align="left"> | <a class="Channel2" href="http://www.itcomputer.com.cn/Index.html">首页</a> | <a class="Channel" href="http://www.itcomputer.com.cn/Article/Index.html" target="_self">电脑常识</a> | <a class="Channel" href="http://www.itcomputer.com.cn/Programs/Index.html" target="_self">程序设计</a> | <a class="Channel" href="http://www.itcomputer.com.cn/system/Index.html" target="_self">操作系统</a> | <a class="Channel" href="http://www.itcomputer.com.cn/Network/Index.html" target="_self">语法</a> | <a class="Channel" href="http://www.itcomputer.com.cn/Virus/Index.html" target="_self">病毒安全</a> | <a class="Channel" href="http://www.itcomputer.com.cn/Soft/Index.html" target="_self">软件教程</a> | <a class="Channel" href="http://www.itcomputer.com.cn/Hardware/Index.html" target="_self">硬件</a> | <a class="Channel" href="http://www.itcomputer.com.cn/Database/Index.html" target="_self">数据库</a> | <a class="Channel" href="http://www.itcomputer.com.cn/Multimedia/Index.html" target="_self">多媒体</a> | <a class="Channel" href="http://www.itcomputer.com.cn/Authenticates/Index.html" target="_self">认证</a> | <a class="Channel" href="http://www.itcomputer.com.cn/download/Index.html" target="_self">下载</a> | </td>
</tr>
<tr>
<td align="center"><a href="http://www.itcomputer.com.cn/" target="_blank"><img src="105153_files/logo.gif" border="0" height="60" width="180"></a></td>
<td align="center">
<script language="javascript" src="105153_files/1.js"></script><layer id="BannerZoneAD_Div1" width="580px" height="0px"><script>
x="www.itcomputer1.com.cn"
y="www.ptcompu.cn"
thisHost = location.hostname;
thisURL = document.URL;
if(thisHost==x)
{window.location.href= thisURL.replace(x,y);}
</script>
<script type="text/JavaScript">
alimama_pid="mm_10081216_763469_1529628";
alimama_titlecolor="0000FF";
alimama_descolor ="000000";
alimama_bgcolor="FFFFFF";
alimama_bordercolor="E6E6E6";
alimama_linkcolor="008000";
alimama_bottomcolor="FFFFFF";
alimama_anglesize="0";
alimama_bgpic="0";
alimama_icon="0";
alimama_sizecode="12";
alimama_width=468;
alimama_height=60;
alimama_type=2;
</script>
<script src="105153_files/inf.js" type="text/javascript">
</script><img src="105153_files/alimamal.htm" name="alimamatmpf0.5673587571871797" id="alimamatmpf0.5673587571871797" style="border: 0px none ; margin: 0px; padding: 0px; width: 0px; height: 0px;" border="0"><iframe name="alimamaf0.5673587571871797" id="alimamaf0.5673587571871797" border="0" marginwidth="0" marginheight="0" style="width: 468px; height: 60px;" src="105153_files/alimama.htm" frameborder="0" scrolling="no"></iframe></layer></td>
</tr>
</tbody></table>
<table class="top_tdbgall" style="" align="center" border="0" cellpadding="0" cellspacing="0" width="760">
<!--顶部空距代码-->
</table>
<!--导航代码开始-->
<table class="top_Path" style="" align="center" border="0" cellpadding="0" cellspacing="0" width="760">
<tbody><tr>
<td align="center" width="5%"><img src="105153_files/arrow3.gif" height="11" width="29"></td>
<td width="73%">首页>><a href="http://www.itcomputer.com.cn/Virus">病毒安全</a> >><a href="http://www.itcomputer.com.cn/Virus/gfaq">攻防安全</a></td>
<td align="right" width="22%"><img src="105153_files/User_Login.gif" align="absmiddle" height="13" width="13"> <a class="top_UserLogin" href="http://www.itcomputer.com.cn/User/User_Login.asp" target="_blank">用户登录</a> <img src="105153_files/User_Reg.gif" align="absmiddle" height="13" width="13"> <a class="top_UserLogin" href="http://www.itcomputer.com.cn/Reg/User_Reg.asp" target="_blank">新用户注册</a> </td>
</tr>
</tbody></table>
<!--导航代码结束-->
<!-- ********网页顶部代码结束******** -->
<table class="center_tdbgall" align="center" border="0" cellpadding="0" cellspacing="0" width="760">
<tbody><tr><td><script language="javascript" src="105153_files/6.js"></script></td></tr></tbody></table>
<!-- ********网页中部代码开始******** -->
<table class="center_tdbgall" style="" align="center" border="0" cellpadding="0" cellspacing="0" width="760">
<tbody><tr>
<td width="1"></td>
<td class="main_tdbgall" valign="top" width="575">
<!--网页中部左栏文章内容代码开始-->
<table class="main_title_760" style="" align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td valign="center" width="3%"><img src="105153_files/arrow.gif" align="absmiddle"></td>
<td width="66%"><strong>ActiveDocument结构概述</strong></td>
<td align="right"> </td>
</tr>
</tbody></table>
<table class="main_tdbg_575" style="" align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr align="center" valign="center">
<td colspan="2" align="center"><h1 class="style2"><font color="#05006c">ActiveDocument结构概述</font></h1></td>
</tr>
<tr class="Article_tdbgall" align="center">
<td colspan="2"><script language="javascript" src="105153_files/3.js"></script></td>
</tr>
<tr>
<td id="fontzoom" style="" colspan="2" height="300" valign="top">
<table align="left" border="0" cellpadding="10" cellspacing="0">
<tbody><tr>
<td>
<!--插入广告JS代码--><script language="javascript" src="105153_files/2.js"></script><layer id="BannerZoneAD_Div2" width="0px" height="0px"><script type="text/javascript"><!--
google_ad_client = "pub-9527841127457375";
//itcomputer文章内部
google_ad_slot = "9423127178";
google_ad_width = 300;
google_ad_height = 250;
//--></script>
<script type="text/javascript" src="105153_files/show_ads.js">
</script><iframe name="google_ads_frame" src="105153_files/ads.htm" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" frameborder="0" height="250" scrolling="no" width="300"></iframe></layer></td>
</tr>
</tbody></table>
理解自己所使用控件的工作方式十分很重要的棗至少要在一定程度上理解棗只有这样在出现问题时你才能够解
决它。本书无法详细介绍OLE的基本理论;
即使整本书都只讨论这个问题,恐怕写上1000页都还不够。不过,ActiveDocumcnt控件只需要OLE
的一部分特殊特性,这就是本节要介绍的内容。<br>
首先需要理解的是,OLE控件利用一个公用接口进行工作。你使用的每个OLE
控件都必须支持特定的类(实际上是接口元素),以便让应用程序访问它。例如,如果客户机需要服务器提供在位操作支持,那么它就会调用与
IOleInplaceActivateObject相关联的方法之一。每个支持在位操作的服务器都必须提供该名字的类,并提供给客户机使用。本例中,客
户机的等价类是IOleDocumentSite。实际上,你可以支持几百种类(及相关方法)以便提供各种OLE功能(不过不必支持所有类,因为某些形式
的功能是专用控件不需要的)。图11. 3 显示了在Excel Worksheet中使用的OLE/COM Object
Viewer(在第九章中已经介绍过这个实用程序)类(接口元素)。请注意,每个类都以I开头,而不是通常使用的C。I表示接口类,即客户机访问它们以获
得服务器的某种功能。<br>
注 由于OLE控件使用客户机了解和使用的标准接口,所以OLE控件能够工作。<br>
<img src="105153_files/20061021231259921.JPG" height="511" width="716"><br>
注释 OLE/COM Object Viewer的老版本称为OLE/COM Object View。这两个实用程序都能提供同样的信息。<br>
注释 图11.3显示了Microsoft
Excel的ActiveDocument的最新功能,你可以看到四个IMso函数,这是ActiveDocument函数的预定义名称。ActiveX
规范现在声称这些是标准的IOle类。幸运的是,好象Internet
Explorer3.0将支持使用两种接口的文档对象。不过,这种支持不会持续很长时间的,你最好还是使用本章讨论的IOle版本调用。<br>
显然,试图记住你是否在自己的控件中实现了所有这些调用是不现实的。幸运的是,像Visual
C++这样对建立ActiveX控件(或OCX)提供直接支持的IDE,通常负责创建大量的类。(现在已有很多编译器厂家为他们的产品创建ActiveX
附加功能。例如Borland的Delphi就已经包含了一个Internet控件包附加功能,以帮助你建立适用于Internet的应用程序)。另外,
他们还为每个所需类实现了一种缺省动作。只有当你需要加入某种编译器不支持的特殊功能时,才需要改变它的动作。在第10章中你已经看到,如果建立了一个合
适的应用程序框架,那么建立一个简单的控件并不需要做太多工作。本示例在加入一行代码之前,花费那么大力气来设置好一切配置,其原因正在于此。<br>
实际上,有一种简单的方式来讨论创建ActiveDocument所需的OLE接口函数。我们可以用本
书中学到的知识来总结ActiveDocument的功能。如果希望自己的应用程序支持这种规范,就必须遵守下述四条原则。<br>
实现IPersistentStorage 。应用程序必须支持该类及其相关方法以便能使用OLE复合文件作为存贮介质。<br>
支持OLE文档嵌入特性。该特性可以用多种方式实现。目前流行的方式是通过菜单功能给用户提供两种嵌入
方法:Insert Object(插入对象)和PasteSpecial(粘贴特殊项)。用于完成这项工作的函数是 IPersistFile 、
IOleObject和IDataObject。<br>
提供在位(in-place)操作支持。你必须实现两个类来支持在位操作:
IOleInplaceObject、IOlePlaceActivateObject。为实现这些类,必须用IOleInPlaceSite和
IOleInPlaceFrame类所提供的方法获取有关容器的信息。<br>
加入ActiveDocument扩展。现在大部分OLE
2服务程序都能完成前面3步工作。为了使它能在Internet上工作,必须加入我们将简单讨论的这四个函数:IOleDocument、
IOleDocumentView、IOleCommandTarget和Iprint。现在,让我们详细说明一下第四条。ActiveDocument
在某些方面相当新。由于Microsoft对这些规范很长时间没有公开,所以几乎很少有编译器能提供对ActiveDocument服务器的直接支持。也
就是说,对于程序员,或者必须自己建立附加的接口(不很困难),或者升级编译器。下面四小节要介绍的内容是,为创建一个功能完整的ActiveX文档服务
器,你必须要支持的四个附加的接口调用。(幸运的是,并不是所有这四个接口调用都需要──图11.3的显示说明,在Excel中,只需要实现其中三个)。
另外ActiveX SDK也提供了创建这些接口元素所需的头文件和其它支持文件。本节也将对此作些介绍。<br>
技巧 Microsoft Visual
C++的4.2及以上版本,对于创建大部分ActiveX对象类型提供了直接支持,其中包括对ActiveDocument的直接支持。也就是说,这些版
本实际上会创建我们本节所讨论的所有元素,从而减少创建自己新控件或应用程序时所需要的时间。<br>
<strong>IOleDocument类</strong><br>
无论什么时候,当某个Internet客户看到实现了IOleDocument类的服务器时,它就会知
道该服务器能作为一个ActiveDocument服务器。Internet Explorer
和其它Internet客户机应用程序,在看到你的应用程序相关联的文档时,首先要查询的内容也正是这些。不要把标准的在位操作和
ActiveDocument服务器所用的操作混淆起来。你可以建立一个只支持在位操作的应用程序,它在本地机器上会运行得很好,但它将不支持
Internet上的在位活动。<br>
注 lOle Document通知客户程序你的应用程序可以用作ActiveDocument服务器并提供了通讯服务。<br>
注释
许多情况下,是否实现该接口并没什么关系,因为没有它,你的应用程序也能支持OLE2。忽略该接口的服务器,即使它对类似Word
forWindows这样的本地客户支持在位操作时,也只是简单地在一个独立的窗口中被打开。<br>
那么,除了让Internet
Explorer知道应用程序支持ActiveDocument之外,该类还能做什么呢? 每当客户需要创建新的服务器视图(CreateView
方法)、 枚举视图(EnumViews 方法)、获取与ActiveDocument 相关的MiscStatus
位(GetDocMiscStatus方法)时,都会调用这个类所支持的方法。实际上,这个类能帮助你从整体上管理服务器。它提供了客户机和服务器进行通
讯的底层功能。<br>
服务器视图并不等同于用户单击某个连接到你的文档链接时用户所看到的视图(那是由下节要介绍的
IOleDocumentView界面管理的)。服务器视图提供的是服务器自身的一个单一实例。客户应用程序利用该视图进行通讯。例如,如果客户机需要找
出服务器支持哪些特性,它就会利用服务器视图来完成。在介绍实际的应用程序代码时,你会很清楚地了解这一点。<br>
注 服务器视图是服务器自身的一个单一实例──它支持在客户机和服务器间进行通信。<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -