Export (0) Print
Expand All

CView Class

Provides the basic functionality for user-defined view classes.

class AFX_NOVTABLE CView : public CWnd

Name

Description

CView::CView

Constructs a CView object.

Name

Description

CView::DoPreparePrinting

Displays Print dialog box and creates printer device context; call when overriding the OnPreparePrinting member function.

CView::GetDocument

Returns the document associated with the view.

CView::IsSelected

Tests whether a document item is selected. Required for OLE support.

CView::OnDragEnter

Called when an item is first dragged into the drag-and-drop region of a view.

CView::OnDragLeave

Called when a dragged item leaves the drag-and-drop region of a view.

CView::OnDragOver

Called when an item is dragged over the drag-and-drop region of a view.

CView::OnDragScroll

Called to determine whether the cursor is dragged into the scroll region of the window.

CView::OnDrop

Called when an item has been dropped into the drag-and-drop region of a view, default handler.

CView::OnDropEx

Called when an item has been dropped into the drag-and-drop region of a view, primary handler.

CView::OnInitialUpdate

Called after a view is first attached to a document.

CView::OnPrepareDC

Called before the OnDraw member function is called for screen display or the OnPrint member function is called for printing or print preview.

CView::OnScroll

Called when OLE items are dragged beyond the borders of the view.

CView::OnScrollBy

Called when a view containing active in-place OLE items is scrolled.

Name

Description

CView::OnActivateFrame

Called when the frame window containing the view is activated or deactivated.

CView::OnActivateView

Called when a view is activated.

CView::OnBeginPrinting

Called when a print job begins; override to allocate graphics device interface (GDI) resources.

CView::OnDraw

Called to render an image of the document for screen display, printing, or print preview. Implementation required.

CView::OnEndPrinting

Called when a print job ends; override to deallocate GDI resources.

CView::OnEndPrintPreview

Called when preview mode is exited.

CView::OnPreparePrinting

Called before a document is printed or previewed; override to initialize Print dialog box.

CView::OnPrint

Called to print or preview a page of the document.

CView::OnUpdate

Called to notify a view that its document has been modified.

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.

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.

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.

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.

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.

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.

Besides CScrollView, the Microsoft Foundation Class Library provides nine other classes derived from CView:

  • CCtrlView, a view that allows usage of document - view architecture with tree, list, and rich edit controls.

  • CDaoRecordView, a view that displays database records in dialog-box controls.

  • 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.

  • CFormView, a scrollable view that contains dialog-box controls and is based on a dialog template resource.

  • CListView, a view that allows usage of document - view architecture with list controls.

  • CRecordView, a view that displays database records in dialog-box controls.

  • CRichEditView, a view that allows usage of document - view architecture with rich edit controls.

  • CScrollView, a view that automatically provides scrolling support.

  • CTreeView, a view that allows usage of document - view architecture with tree controls.

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, see Document/View Architecture and Printing. In addition, see Technical Note 30 for more details on customizing print preview.

Header: afxwin.h

Show:
© 2014 Microsoft