Brief Full Advanced Search Search Tips
|  |  | To access the contents, click the chapter and section titles. Fast Track Visual C++ 6.0 Programming (Publisher: John Wiley & Sons, Inc.) Author(s): Steve Holzner ISBN: 0471312908 Publication Date: 09/01/98 Search this book:
Previous | Table of Contents | Next
## Chapter 3 Edit Views, HTML Views, Tree Views, Splitter Windows, and More In the last chapter, we looked at MDI programming and started supporting multiple views in documents. In this chapter, we look at the different kinds of views that the MFC library already supports—and there’s a lot of rich programming here. We see how to use rich edit views that display and edit rich (formattable) text, HTML views that connect to the Internet, tree views that display trees of nodes that can open or close like the folders in the Windows Explorer, form views that let you place controls directly on them just like a dialog box, and splitter windows (note that splitters are actually windows, not views). Being able to select prewritten view types is one of the most powerful aspects of Visual C++. Imagine, for example, having to write all the code to support rich text—different fonts, text and paragraph formatting, different font sizes, italics, bold face fonts, and much more. All this and more—such as being able to read files from disk and to write them out again—is already done for you when you use the rich edit view, which we look at first. ### Rich Text Views There are two edit views in the MFC: edit views and rich edit views. Simple edit views are pretty basic, and we’ve already seen how to put them to use in Chapter 2, “Multiple Documents, Multiple Views,” where we mixed edit views with standard MDI views in a program. We need to look at the more powerful rich edit views here to be able to do all that standard edit views do and more: format our text. Rich text format (RTF), is a special text format that supports all kinds of formatting options. It was first created to allow documents to be passed between incompatible word processors. You can write RTF documents in word processors like Microsoft Word and save them in RTF format, which supports many of the text options available in word processors such as Word. Let’s put rich edit views to work in a new project, RichEditView. Create the project as an MDI project and work through AppWizard all the way to Step 6, as shown in Figure 3.1. To install the rich edit view, make sure the view class is selected in the Class name box of AppWizard (in this case, the view class is the somewhat awkwardly named CRichEditViewView) and select CRichEditView as the base class, as shown in Figure 3.1. Click Finish to create the new project. Figure 3.1 Creating a rich edit view. #### The New Document Template We’ve created a new document template in RichEditView.cpp, which uses the rich edit view class, CRichEditView, as its view.
        CMultiDocTemplate* pDocTemplate;
        pDocTemplate = new CMultiDocTemplate(
            IDR_RICHEDTYPE,
            RUNTIME_CLASS(CRichEditViewDoc),
            RUNTIME_CLASS(CChildFrame), // custom MDI child frame
            RUNTIME_CLASS(CRichEditViewView));        ⇐
        pDocTemplate->SetContainerInfo(IDR_RICHEDTYPE_CNTR_IP);
        AddDocTemplate(pDocTemplate);
The CRichEditView class’s member functions appear in Table 3.1.
Table 3.1 CRichEditView Class’s Functions
Function | Does this
--- | ---
AdjustDialogPosition | Moves a dialog box so that it doesn’t obscure the current selection.
CanPaste | Tells whether the Clipboard contains data that can be pasted into the rich edit view.
CRichEditView | Constructs a CRichEditView object.
DoPaste | Pastes an OLE item into this rich edit view.
FindText | Finds the specified text, invoking the wait cursor.
FindTextSimple | Finds the specified text.
GetCharFormatSelection | Retrieves the character formatting attributes for the current selection.
GetClipboardData | Retrieves a Clipboard object for a range in this rich edit view.
GetContextMenu | Retrieves a context menu to use on a right mouse-button down.
GetDocument | Retrieves a pointer to the related CRichEditDoc.
GetInPlaceActiveItem | Retrieves the OLE item that is currently in place and active in the rich edit view.
GetMargins | Retrieves the margins for this rich edit view.
GetPageRect | Retrieves the page rectangle for this rich edit view.
GetPaperSize | Retrieves the paper size for this rich edit view.
GetParaFormatSelection | Retrieves the paragraph formatting attributes for the current selection.
GetPrintRect | Retrieves the print rectangle for this rich edit view.
GetPrintWidth | Retrieves the print width for this rich edit view.
GetRichEditCtrl | Retrieves the rich edit control.
GetSelectedItem | Retrieves the selected item from the rich edit view.
GetTextLength | Retrieves the length of the text in the rich edit view.
InsertFileAsObject | Inserts a file as an OLE item.
InsertItem | Inserts a new item as an OLE item.
IsRichEditFormat | Tells whether the clipboard contains data in a rich edit or text format.
IsSelected | Indicates whether the given OLE item is selected.
OnCharEffect | Changes the character formatting for the current selection.
OnFindNext | Finds the next occurrence of a substring.
OnInitialUpdate | Refreshes a view when it is first attached to a document.
OnParaAlign | Changes the alignment of paragraphs.
OnPasteNativeObject | Retrieves native data from an OLE item.
OnPrinterChanged | Sets the print characteristics to the given device.
OnReplaceAll | Replaces all occurrences of a given string with a new string.
OnReplaceSel | Replaces the current selection.
OnTextNotFound | Handles user notification that the requested text was not found.
OnUpdateCharEffect | Updates the Command UI for character public member functions.
OnUpdateParaAlign | Updates the Command UI for paragraph public member functions.
PrintInsideRect | Formats the specified text within the given rectangle.
PrintPage | Formats the specified text within the given page.
QueryAcceptData | Queries to see about the data on the IDataObject.
SetCharFormat | Sets the character formatting attributes for the current selection.
SetMargins | Sets the margins for this rich edit view.
SetPaperSize | Sets the paper size for this rich edit view.
SetParaFormat | Sets the paragraph formatting attributes for the current selection.
WrapChanged | Adjusts the target output device for this rich edit view based on the value of m_nWordWrap.
Previous | Table of Contents | Next

| Products | Contact Us | About Us | Privacy | Ad Info | Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.