MFC Text Editing Options

Windows itself supplies two text editing tools: edit control and Windows rich edit common control. Both can be used as controls within dialogs, but both can also be made to look like view windows. The MFC library supports this versatility with the CEditView and CRichEditView classes.

The CEditView Class

This class is based on the Windows edit control, so it inherits all the edit control's limitations. Text size is limited to 64 KB, and you can't mix fonts. AppWizard gives you the option of making CEditView the base class of your view class. When the framework gives you an edit view object, it has all the functionality of both CView and CEdit. There's no multiple inheritance here, just some magic that involves window subclassing. The CEditView class implements and maps the clipboard cut, copy, and paste functions, so they appear active on the Edit menu.

The CRichEditView Class

This class uses the rich edit control, so it supports mixed formats and large quantities of text. The CRichEditView class is designed to be used with the CRichEditDoc and CRichEditCntrItem classes to implement a complete ActiveX container application.

The CRichEditCtrl Class

This class wraps the rich edit control, and you can use it to make a fairly decent text editor. That's exactly what we'll do in the EX13A example. We'll use an ordinary view class derived from CView, and we'll cover the view's client area with a big rich edit control that resizes itself when the view size changes. The CRichEditCtrl class has dozens of useful member functions, and it picks up other functions from its CWnd base class. The functions we'll use in this chapter are as follows.

FunctionDescription
CreateCreates the rich edit control window (called from the parent's WM_CREATE handler)
SetWindowPosSets the size and position of the edit window (sizes the control to cover the view's client area)
GetWindowTextRetrieves plain text from the control (other functions available to retrieve the text with rich text formatting codes)
SetWindowTextStores plain text in the control
GetModifyGets a flag that is TRUE if the text has been modified (text modified if the user types in the control or if the program calls SetModify(TRUE))
SetModifySets the modify flag to TRUE or FALSE
GetSelGets a flag that indicates whether the user has selected text
SetDefaultCharFormatSets the control's default format characteristics
SetSelectionCharFormatSets the format characteristics of the selected text

If you use the dialog editor to add a rich edit control to a dialog resource, your application class InitInstance member function must call the function AfxInitRichEdit.



Programming Microsoft Visual C++
Programming Microsoft Visual C++
ISBN: 1572318570
EAN: 2147483647
Year: 1997
Pages: 332

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net