于富文本格式的剪贴板的实现
详细信息    本馆镜像全文|  推荐本文 |  |   获取CNKI官网全文
  • 英文题名:The Implementation of Clipboard Based on Rich Text Format
  • 作者:佟伟
  • 论文级别:硕士
  • 学科专业名称:计算机应用技术
  • 学位年度:2004
  • 导师:赫枫龄
  • 学科代码:081203
  • 学位授予单位:吉林大学
  • 论文提交日期:2004-04-01
摘要
富文本格式(Rich Text Format)是Microsoft公司所开发的一种规格说明,这种规格说明是一种将格式化文本和图形进行编码的方法,目的是使得在各种应用程序之间传递文本和图形变得更容易。在 Windows操作系统中(Word6.0及以后版本)所创建的富文本格式文件,具有“.rtf”的文件扩展名。富文本格式目前已经成为一种非常流行的文件结构,很多文字编辑器都支持它,VB等开发工具甚至还提供了RichTextBox控件。
    剪贴板是应用程序间进行静态数据交换极为有用的工具。实际上,它并不是一个独立的应用程序,而是在Windows系统中单独预留出来的一块内存,用来暂时存放在Windows应用程序之间需要交换的数据。Windows给我们提供了操纵剪贴板的API函数(应用程序编程接口函数),各种应用程序通过调用这些函数来管理应用程序与剪贴板之间所进行的数据交换。
    富文本格式文件与我们熟知的Word文件.doc的表达能力相同。但是,富文本格式文件更具优势。首先,对富文本格式编程更加可行。富文本格式以ASCII码的形式对文本与图形等对象进行描述,具有人工可读性,是一种ASCII码文件编码方式。其次,这些年里它已经显得稳定多了,并且我们容易对它的改变进行跟踪。最后,富文本格式还具有安全性方面的优势:它不太可能被病毒感染。在一些有丰富经验的网络管理员所管理的一些网络上,他们进行了流量限制:把.doc排除在外,而赞成使用富文本格式,以预防恶意代码。这些方面都是二进制文件编码方式.doc所不具备的和欠缺的。
    富文本格式具有如上所述的明显优势,目前又如此的流行,这些因素使得那些编写通用工具的程序员应该考虑在自己的软件中加入输入输出富文本格式文件的功能。作为读写富文本格式文件的一个具体实例,本文讨论了在富文本格式文件与剪贴板之间的数据转换。
    建立基于富文本格式的剪贴板就是架设富文本格式文件与剪贴板之间进行数据交换的桥梁。根据“架设桥梁”所利用的“地基”的不同,
    
    
    我们可以将转换途径区分为直接方法和间接方法。所谓的“直接方法”,就是直接分析富文本格式,记录下各种格式信息,然后在程序中重新构造出对象。所谓的“间接方法”,就是利用Windows已经具备的功能,通过某些软件技术,调用Windows的底层API函数建立联系。
    本文系统地介绍了富文本格式与剪贴板的概念,讨论了在Microsoft Visual C++开发环境下,利用微软基础类库MFC与组件对象模型COM技术在建立基于富文本格式的剪贴板中的应用。本文主要做了以下四方面的工作:
    1 富文本格式
    富文本格式的结构并不复杂,但是内容繁多。本文从总体上阐述了富文本格式的语法,使得我们对它有一个清晰的认识。通过大量地仔细地阅读关键字并理解它们各自的意义,本文将它们依照语法功能进行分类与归纳,给出了在编程中所首要注意的部分富文本格式语法的范式描述。这些工作对建造富文本格式分析与构造程序,对程序的可扩展性都具有很大的帮助。
    2 剪贴板
    为了更深层次的观察与了解剪贴板的内容,笔者编写了一个处理剪贴板上的数据的实用工具。它是一个极具吸引力的剪贴板察看程序,是富文本格式分析与构造程序的一个重要组成部分。它也可以观察拖放操作中的数据。
    3 富文本格式分析器与构造器的间接实现方法
    本文实现了四种实现富文本格式与剪贴板之间的数据交换的间接方法。
    第一种方法基于Visual C++MFC应用程序框架。这种方法的实质是利用Visual C++的MFC应用程序框架所提供的支持。这些支持包括:富文本格式与视图之间,视图与剪贴板之间的数据传送的支持。
    第二种方法基于Visual C++MFC类CRichEditView。这种方法的实质是利用视图类CRichEditView所封装的控制类CRichEditCtrl对富文本格式流进行操作。
    第三种方法基于Visual C++的OLE自动化客户端。这种方法的实质是利用组件对象模型COM技术,调用Windows系统下的字处理软件Word的编程接口API函数,对富文本格式文件进行操作。
    第四种方法基于Visual C++MFC在视图中嵌入Word。这种方法的实质是利用组件对象模型COM技术,将Windows系统的字处理软件Word嵌入到应用程序的客户区当中,使用Word所提供的所有功能对富文本格式文件进行操作。
    
    4 富文本格式分析器的直接实现方法
    本文采用一种表驱动的方法分析富文本格式。具体来说就是把富文本格式文件的段落、颜色、字体等风格,在程序中用一些数据结构把这些信息存起来,再根据要求进行显示或转换。这种方法使得程序在扫描富文本格式的时候具备最大的灵活性,当然它同时也存在着难于检测出不正确的富文本格式的问题。本文对在开发过程中遇到的问题,例如:汉字的显示,进行了简要的论述。
The Rich Text Format (RTF) Specification developed by Microsoft is a method of encoding formatted text and graphics for easy transfer between applications on different operating systems. RTF files created in Word 6.0 (and later) for Windows have a file type of “.RTF”. Currently, the Rich Text Format has already been such a sort of widely used file structures that many word-processing editors support it, and, what's more, software-developing tools such as VB provide RichTextBox control.
    Clipboard is an extremely useful tool that helps applications exchange data statically. Actually, it is not a self-governed application, but a block of memory allocated separately and in advance under Windows and a temporary region used for storing data transmitted between applications. Windows offers us functions called Application Programming Interface (API) to assist applications in manipulating clipboard.
    The expression ability of RTF is equal to that of .doc known as a kind of Word file formats. However, the Rich Text Format possesses more advantages. Firstly, it is more feasible to program RTF, for RTF is an ASCII-encoding mode and the content is readable. Secondly, RTF is almost free from change and it is easy for us to trace its variations. Finally, RTF is prior in the aspect of security for it is unlikely infected by viruses. All above are shortcomings of the binary-encoding mode .doc.
    It is as a result of these obvious merits and its popularity that those programmers who write all-propose tools should consider to add the function of inputting and outputting RTF files to their own works. As an instance of reading and writing RTF files, this paper is concerned with the data transfer between RTF files and clipboard.
    To establish a clipboard based on RTF is to build a "bridge" between RTF files and clipboard. According to the "groundwork" of the bridge, we can divide the transfer methods into two classes: "direct means", which analyze
    
    
    RTF and reconstruct the formatted objects, and "indirect means", which utilize the API functions existed in Windows.
    This article systemically introduce the conception of RTF and clipboard, and then discuss the application using Microsoft Foundation Class(MFC) and Component Object Model(COM) in establishing a clipboard based on RTF under the developing environment of MS Visual C++.
    This paper mainly includes works on four subjects:
    1 Rich Text Format
    Although the structure of RTF is not sophisticated, the content of RTF is various. By the means of reading keywords and comprehending their effection, this paper categorizes them by syntax function and describes a part of RTF, which should be chiefly noticed, using the formal syntax based on Backus-Naur Form. The formal syntax has a great help in building a RTF analyzer and constructor and the expansibility of the program.
    2 Clipboard
    For seeing deeper into the contents of the clipboard, this article provides a utility that deals with HDROP data on the clipboard. It is an especially attractive clipboard viewer and an important part of the ultimate analyzer and constructor. It can also acquaint us with the data in a drag-and-drop operation.
    3 indirect means to establish a RTF analyzer and constructor
    This paper implements four indirect ways to found the data exchanging paths between RTF and Clipboard.
    The first means is based on Visual C++ MFC Application Frame. The essence of this method is to harness the characters furnished by MFC Application Frame, including the support of data transfer between RTF and View and that between View and Clipboard.
    The second means is based on the class CRichEditView in Visual C++ MFC. The essence of this method is to use the class CRichEditView, which encapsulate the class CRichEditCtrl, to manipulate the RTF stream.
    The third means is based on the OLE automation client. The essence of this method is to make use of COM to call the API functions of Word in order to navigate RTF files.
    The fourth means is based on embedding Word into the view. The essence of this method is to employ COM to inlay
引文
[1](美)Charles Petzold著,北京博彦科技发展有限公司译,Windows程序设计(第五版),北京大学出版社,1999,531-553。
    [2](美)Steve Teixeira,Xavier Pacheco著,任旭钧等译,Delphi 5开发人员指南,机械工业出版社,2000,539-547。
    [3](美)David J.Kruglinski著,潘爱民﹑王国印译,Visual C++技术内幕(第四版),清华大学出版社,1999,395-406。
    [4] (美)David J.Kruglinski著,潘爱民﹑王国印译,Visual C++技术内幕(第四版),清华大学出版社,1999,587-592。
    [5] 潘爱民,COM原理与应用,清华大学出版社,1999.1,第一版,272-300。
    [6](美)Charles Petzold著,北京博彦科技发展有限公司译,Windows程序设计(第五版),北京大学出版社,1999,159-176。
    [7](美)Charles Petzold著,北京博彦科技发展有限公司译,Windows程序设计(第五版),北京大学出版社,1999,65-108。
    [8](美)Charles Petzold著,北京博彦科技发展有限公司译,Windows程序设计(第五版),北京大学出版社,1999,931-1023。
    [9](美)Charles Petzold著,北京博彦科技发展有限公司译,Windows程序设计(第五版),北京大学出版社,1999,1025-1096。
    [10](美)David J.Kruglinski著,潘爱民﹑王国印译,Visual C++技术内幕(第四版),清华大学出版社,1999,619-667。
    [11](美)Charles Petzold著,北京博彦科技发展有限公司译,Windows程序设计(第五版),北京大学出版社,1999,193-250。
    [12](美)David J.Kruglinski著,潘爱民﹑王国印译,Visual C++技术内幕(第四版),清华大学出版社,1999,467-503。
    [13](美)Ash Rofail,Yasser Shohoud(著),邱仲潘等(译),COM与COM+从入门到精通,电子工业出版社,2000,1-92。
    [14](美)Box,D.著, 潘爱民(译),COM本质论,中国电力出版社,2001,1-217。
    [15]潘爱民,COM原理与应用,清华大学出版社,1999.1,第一版,139-174。
    [16](美)Dale Rogerson著,杨秀章译,COM技术内幕:微软组件对象模型,清华大学出版社,1999.3,第一版,225-252。
    
    [17](美)Corry, Mayfield, Cadman著,刘云﹑孔雷译,COM/DCOM编程技术内幕,清华大学出版社,2000,36-166。
    [18](美)Steve Teixeira,Xavier Pacheco著,任旭钧等译,Delphi 5开发人员指南,机械工业出版社,2000,712-794。
    [19](美)David J.Kruglinski著,潘爱民﹑王国印译,Visual C++技术内幕(第四版),清华大学出版社,1999,504-567。
    [20]潘爱民,COM原理与应用,清华大学出版社,1999.1,第一版,333-414。

© 2004-2018 中国地质图书馆版权所有 京ICP备05064691号 京公网安备11010802017129号

地址:北京市海淀区学院路29号 邮编:100083

电话:办公室:(+86 10)66554848;文献借阅、咨询服务、科技查新:66554700