CDocument - MSDN6翻译交流

来源:互联网 发布:kali linux共享文件夹 编辑:程序博客网 时间:2024/04/30 22:01

BUG和建议请提出,谢谢!

CDocument

The CDocument class provides the basic functionality for user-defined document classes. A document represents the unit of data that the user typically opens with the File Open command and saves with the File Save command.

CDocument类为用户定义的文档类提供基本的功能。文档描述了用户(typically)使用“文件打开命令”打开的和使用“文件保存命令”保存的数据单位。

CDocument supports standard operations such as creating a document, loading it, and saving it. The framework manipulates documents using the interface defined by CDocument.

CDocument支持像创建一个文档,装载它和保存它这样的标准操作。框架使用CDocument定义的接口来操纵文档。

An application can support more than one type of document; for example, an application might support both spreadsheets and text documents. Each type of document has an associated document template; the document template specifies what resources (for example, menu, icon, or accelerator table) are used for that type of document. Each document contains a pointer to its associated CDocTemplate object.

一个应用能够支持多于一种类型的文档;例如,一个应用可以同时支持电子表格和文本文档。每个类型的文档(都)有一个关联的文档模板,此文档模板指定了那种类型的文档使用了什么资源(例如,菜单、图标和(快捷键表))。每个文档包都含一个指向其关联的CDocTemplate物件的指针。

Users interact with a document through the CView object(s) associated with it. A view renders an image of the document in a frame window and interprets user input as operations on the document. A document can have multiple views associated with it. When the user opens a window on a document, the framework creates a view and attaches it to the document. The document template specifies what type of view and frame window are used to display each type of document.

用户通过与文档关联的CView物件来与文档进行交互。视图(实现了)文档(的内容)在框架窗口中的显示(表现),并且将用户的输入(解释为)对文档的操作。一个文档可以有多个与其相关联的视图。当用户在文档上打开了一个窗口时,(框架)(将)创建一个视图并关联到此文档。文档模板指定了每个类型的文档使用什么类型的视图和框架窗口。

Documents are part of the framework’s standard command routing and consequently receive commands from standard user-interface components (such as the File Save menu item). A document receives commands forwarded by the active view. If the document doesn’t handle a given command, it forwards the command to the document template that manages it.

文档是(框架的)标准命令路由的的一部分,因此可以从像“文件保存”菜单项那样的标准用户接口部件接收命令。文档接收由活动视图传递的命令。如果文档没有处理授予的命令,它(将)传递此命令至管理它的文档模板。

When a document’s data is modified, each of its views must reflect those modifications. CDocument provides the UpdateAllViews member function for you to notify the views of such changes, so the views can repaint themselves as necessary. The framework also prompts the user to save a modified file before closing it.

当文档的数据被修改了,他的每一个视图必须反映出那些改动。CDocument为你提供了UpdateAllViews成员函数来通报这些改变的视图,因此这些视图可以在需要时自行重绘。框架也(会)提示用户在关闭(文档)前保存已修改的(文档)。

To implement documents in a typical application, you must do the following:

为了在一个典型的应用中实现文档,你必须做下列事情:

  • Derive a class from CDocument for each type of document.
  • 为每个类型的文档从CDocument继承一个(新)类。
  • Add member variables to store each document’s data.
  • 添加成员变量以保存每个文档的数据。
  • Implement member functions for reading and modifying the document’s data. The document’s views are the most important users of these member functions.
  • 实现用于读取和修改文档数据的成员函数。文档的视图是这些成员函数的一个非常重要的使用者。
  • Override the CObject::Serialize member function in your document class to write and read the document’s data to and from disk.
  • 在你的文档类中覆盖CObject::Serialize成员函数,用于从磁盘读写文档的数据。

CDocument supports sending your document via mail if mail support (MAPI) is present. See the articles MAPI Topics and MAPI Support in MFC in Visual C++ Programmer's Guide.

For more information on CDocument, see Serialization (Object Persistence), Document/View Architecture Topics, and Document/View Creation in Visual C++ Programmer's Guide.

#include <afxwin.h>

Class MembersBase ClassHierarchy Chart

Samples    MFC Sample HELLOMFCSample MDIBINDMFC Sample MDIDOCVWMFC Sample SNAPVWMFC Sample NPP

See Also   CCmdTarget, CView, CDocTemplate

 

原创粉丝点击