BUG和建议请提出,谢谢!
CView
The CView class provides the basic functionality for user-defined view classes. A view is attached to a document and acts as an intermediary between the document and the user: the view renders an image of the document on the screen or printer and interprets user input as operations upon the document.
CView 类为用户(自)定义的视图类提供(最)基本的功能。视图附属于一个文档,扮演着文档和用户之间一个中介。视图(用来)呈现文档在屏幕或是打印机上(所显示)的图象,并将用户的输入(解释为)对文档的操作。
A view is a child of a frame window. More than one view can share a frame window, as in the case of a splitter window. The relationship between a view class, a frame window class, and a document class is established by a CDocTemplate object. When the user opens a new window or splits an existing one, the framework constructs a new view and attaches it to the document.
视图是框架窗口的(子窗口)。多于一个的视图可以共用一个框架窗口,(就像在窗口被分割时那样)。视图类、框架窗口类和文档类三者之间的关系是由一个CDocTemplate 物件来制定的。当用户打开一个新的窗口或是分割一个现有的窗口时,(MFC)框架将构造一个新的视图并使其附属到此文档。
A view can be attached to only one document, but a document can have multiple views attached to it at once — for example, if the document is displayed in a splitter window or in multiple child windows in a multiple document interface (MDI) application. Your application can support different types of views for a given document type; for example, a word-processing program might provide both a complete text view of a document and an outline view that shows only the section headings. These different types of views can be placed in separate frame windows or in separate panes of a single frame window if you use a splitter window.
一个视图只能附属于单个文档,但一个文档能够同时拥有多个隶属于它视图——例如,(
如果
)某个文档被显示在分割的窗口中,或是多文档接口(MDI)应用的多个子窗口中。你的应用(也)能够为给定的文档类型支持不同类型的视图;例如,一个文字处理程序可以为一个文档同时提供一个完整的文本视图和一个只显示(节标题)的大纲视图。这些不同类型的视图能够被安置在独立的框架窗口之中,或是单个框架窗口的独立的窗格之中(如果你使用分割窗口的话)。
A view may be responsible for handling several different types of input, such as keyboard input, mouse input or input via drag-and-drop, as well as commands from menus, toolbars, or scroll bars. A view receives commands forwarded by its frame window. If the view does not handle a given command, it forwards the command to its associated document. Like all command targets, a view handles messages via a message map.
视图可以负责处理几种不同类型的输入,像是键盘输入、鼠标输入或是通过拖放的输入,还有来自菜单、工具栏或和滚动条的命令。视图接受由其框架窗口传入命令。如果此视图没有处理给定的命令,它将把此命令传给其关联的文档。和所有的命令目标一样,视图通过消息映射来处理消息。
The view is responsible for displaying and modifying the document’s data but not for storing it. The document provides the view with the necessary details about its data. You can let the view access the document’s data members directly, or you can provide member functions in the document class for the view class to call.
视图负责了文档数据的显示和修改但不(负责其)存储。文档为视图提供其数据的必要详情。你能够让视图直接访问文档的数据成员,或者你可以在文档类中提供成员函数以供视图类调用。
When a document’s data changes, the view responsible for the changes typically calls the CDocument::UpdateAllViews function for the document, which notifies all the other views by calling the OnUpdate member function for each. The default implementation of OnUpdate invalidates the view’s entire client area. You can override it to invalidate only those regions of the client area that map to the modified portions of the document.
当文档的数据改变时,(负责着变化的)视图(代表性地)调用此文档的CDocument::UpdateAllViews函数,此函数通过调用所有其他的视图的OnUpdate成员函数来通知它们。OnUpdate 默认的执行(将)使视图的全部客户区(都)无效。你可以覆盖(此函数)以仅使那些对应着文档改动部分的客户区域无效。
To use CView, derive a class from it and implement the OnDraw member function to perform screen display. You can also use OnDraw to perform printing and print preview. The framework handles the print loop for printing and previewing your document.
要使用CView,请从它继承一个类并实现OnDraw 成员函数以执行屏幕显示。你也能用OnDraw 来执行打印和打印预览。(MFC)框架(会)处理你的文档的打印及预览的(打印循环)。
A view handles scroll-bar messages with the CWnd::OnHScroll and CWnd::OnVScroll member functions. You can implement scroll-bar message handling in these functions, or you can use the CView derived class CScrollView to handle scrolling for you.
视图使用CWnd::OnHScroll 和CWnd::OnVScroll成员函数来处理滚动条消息。你能够在这些函数中实现对滚动条消息的处理,你也能使用CView 的派生类CScrollView来为你处理滚动(消息)。
Besides CScrollView, the Microsoft Foundation Class Library provides nine other classes derived from CView:
除了CScrollView之外,微软基础类库(还)提供9个其它的继承自CView的类:
- CCtrlView, a view that allows usage of document - view architecture with tree, list, and rich edit controls.
- CCtrlView,(允许将文档——视图体系按树、列表和富编辑控件的用法使用的视图)。
- CDaoRecordView, a view that displays database records in dialog-box controls.
- CDaoRecordView,在对话框控件中显示数据库记录的视图。
- CEditView, a view that provides a simple multiline text editor. You can use a CEditView object as a control in a dialog box as well as a view on a document.
- CEditView,提供简单的多行文本编辑器的视图。你可以使用一个CEditView 物件作为对话框中的控件,(就像在文档上使用视图那样)。
- CFormView, a scrollable view that contains dialog-box controls and is based on a dialog template resource.
- CFormView,一个可滚动的视图,包含对话框控件,是基于对话框模板资源的。
- CListView, a view that allows usage of document - view architecture with list controls.
- CListView,(允许将文档——视图体系按列表控件的用法使用的视图)。
- CRecordView, a view that displays database records in dialog-box controls.
- CRecordView,在对话框控件中显示数据库记录的视图。
- CRichEditView, a view that allows usage of document - view architecture with rich edit controls.
- CRichEditView,(允许将文档——视图体系按富编辑控件的用法使用的视图)。
- CScrollView, a view that automatically provides scrolling support.
- CScrollView,自动提供滚动支持的视图。
- CTreeView, a view that allows usage of document - view architecture with tree controls.
- CTreeView,(允许将文档——视图体系按树控件的用法使用的视图)。
The CView class also has a derived implementation class named CPreviewView, which is used by the framework to perform print previewing. This class provides support for the features unique to the print-preview window, such as a toolbar, single- or double-page preview, and zooming, that is, enlarging the previewed image. You don’t need to call or override any of CPreviewView’s member functions unless you want to implement your own interface for print preview (for example, if you want to support editing in print preview mode). For more information on using CView, seeDocument/View Architecture Topics andPrinting in Visual C++ Programmer’s Guide. In addition, see Technical Note 30 for more details on customizing print preview.
#include <afxwin.h>
Class Members | Base Class | Hierarchy Chart
Samples MFC Sample HELLO | MFC Sample MDIBIND | MFC Sample MDIDOCVW
See Also CWnd, CFrameWnd, CSplitterWnd, CDC, CDocTemplate, CDocument