Programming Microsoft Visual C++
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.
Function | Description |
Create | Creates the rich edit control window (called from the parent's WM_CREATE handler) |
SetWindowPos | Sets the size and position of the edit window (sizes the control to cover the view's client area) |
GetWindowText | Retrieves plain text from the control (other functions available to retrieve the text with rich text formatting codes) |
SetWindowText | Stores plain text in the control |
GetModify | Gets 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)) |
SetModify | Sets the modify flag to TRUE or FALSE |
GetSel | Gets a flag that indicates whether the user has selected text |
SetDefaultCharFormat | Sets the control's default format characteristics |
SetSelectionCharFormat | Sets 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.
Категории