A Rich Edit Control is a window in which the user can enter and edit text. The text can be assigned character and paragraph formatting, and can include embedded OLE objects. It is represented by CRichEditCtrl class.
Sr.No.
Name & Description
1
CanPaste
Determines if the contents of the Clipboard can be pasted into this rich edit control.
2
CanRedo
Determines whether there are any actions in the controls redo queue.
3
CanUndo
Determines if an editing operation can be undone.
4
CharFromPos
Retrieves information about the character closest to a specified point in the client area of an edit control.
5
Clear
Clears the current selection.
6
Copy
Copies the current selection to the Clipboard.
7
Create
Creates the Windows rich edit control and associates it with this CRichEditCtrl object.
8
CreateEx
Creates the Windows rich edit control with the specified extended Windows styles and associates it with this CRichEditCtrl object.
9
Cut
Cuts the current selection to the Clipboard.
10
DisplayBand
Displays a portion of the contents of this CRichEditCtrl object.
11
EmptyUndoBuffer
Resets (clears) the undo flag of this CRichEditCtrl object.
12
FindText
Locates text within this CRichEditCtrl object.
13
FindWordBreak
Finds the next word break before or after the specified character position, or retrieves information about the character at that position.
14
FormatRange
Formats a range of text for the target output device.
15
GetCharPos
Determines the location of a given character within this CRichEditCtrl object.
16
GetDefaultCharFormat
Retrieves the current default character formatting attributes in this CRichEditCtrl object.
17
GetEventMask
Retrieves the event mask for this CRichEditCtrl object.
18
GetFirstVisibleLine
Determines the topmost visible line in this CRichEditCtrl object.
19
GetIRichEditOle
Retrieves a pointer to the IRichEditOle interface for this rich edit control.
20
GetLimitText
Gets the limit on the amount of text a user can enter into this CRichEditCtrl object.
21
GetLine
Retrieves a line of text from this CRichEditCtrl object.
22
GetLineCount
Retrieves the number of lines in this CRichEditCtrl object.
23
GetModify
Determines if the contents of this CRichEditCtrl object have changed since the last save.
24
GetOptions
Retrieves the rich edit control options.
25
GetParaFormat
Retrieves the paragraph formatting attributes in the current selection in this CRichEditCtrl object.
26
GetPunctuation
Retrieves the current punctuation characters for the rich edit control. This message is available only in Asianlanguage versions of the operating system.
27
GetRect
Retrieves the formatting rectangle for this CRichEditCtrl object.
28
GetRedoName
Retrieves the type of the next action, if any, in the control's redo queue.
29
GetSel
Gets the starting and ending positions of the current selection in this CRichEditCtrl object.
30
GetSelectionCharFormat
Retrieves the character formatting attributes in the current selection in this CRichEditCtrl object.
31
GetSelectionType
Retrieves the type of contents in the current selection in this CRichEditCtrl object.
32
GetSelText
Gets the text of the current selection in this CRichEditCtrl object.
33
GetTextLength
Retrieves the length of the text, in characters, in this CRichEditCtrl object. Does not include the terminating null character.
34
GetTextLengthEx
Retrieves the number of characters or bytes in the rich edit view. Accepts a list of flags to indicate the method of determining length of the text in a rich edit control.
35
GetTextMode
Retrieves the current text mode and undo level of a rich edit control.
36
GetTextRange
Retrieves the specified range of text.
37
GetUndoName
Retrieves the type of the next undo action, if any.
38
GetWordWrapMode
Retrieves the current word wrapping and word breaking options for the rich edit control. This message is available only in Asian-language versions of the operating system.
39
HideSelection
Shows or hides the current selection.
40
LimitText
Limits the amount of text a user can enter into the CRichEditCtrl object.
41
LineFromChar
Determines which line contains the given character.
42
LineIndex
Retrieves the character index of a given line in this CRichEditCtrl object.
43
LineLength
Retrieves the length of a given line in this CRichEditCtrl object.
44
LineScroll
Scrolls the text in this CRichEditCtrl object.
45
Paste
Inserts the contents of the Clipboard into this rich edit control.
46
PasteSpecial
Inserts the contents of the Clipboard into this rich edit control in the specified data format.
47
PosFromChar
Retrieves the client area coordinates of a specified character in an edit control.
48
Redo
Redoes the next action in the control's redo queue.
49
ReplaceSel
Replaces the current selection in this CRichEditCtrl object with specified text.
50
RequestResize
Forces this CRichEditCtrl object to send request resize notifications.
51
SetAutoURLDetect
Indicates if the auto URL detection is active in a rich edit control.
52
SetBackgroundColor
Sets the background color in this CRichEditCtrl object.
53
SetDefaultCharFormat
Sets the current default character formatting attributes in this CRichEditCtrl object.
54
SetEventMask
Sets the event mask for this CRichEditCtrl object.
55
SetModify
Sets or clears the modification flag for this CRichEditCtrl object.
56
SetOLECallback
Sets the IRichEditOleCallback COM object for this rich edit control.
57
SetOptions
Sets the options for this CRichEditCtrl object.
58
SetParaFormat
Sets the paragraph formatting attributes in the current selection in this CRichEditCtrl object.
59
SetPunctuation
Sets the punctuation characters for a rich edit control. This message is available only in Asianlanguage versions of the operating system.
61
SetReadOnly
Sets the read-only option for this CRichEditCtrl object.
62
SetRect
Sets the formatting rectangle for this CRichEditCtrl object.
63
SetSel
Sets the selection in this CRichEditCtrl object.
64
SetSelectionCharFormat
Sets the character formatting attributes in the current selection in this CRichEditCtrl object.
65
SetTargetDevice
Sets the target output device for this CRichEditCtrl object.
66
SetTextMode
Sets the text mode or undo level of a rich edit control. The message fails if the control contains text.
67
SetUndoLimit
Sets the maximum number of actions that can stored in the undo queue.
68
SetWordCharFormat
Sets the character formatting attributes in the current word in this CRichEditCtrl object.
69
SetWordWrapMode
Sets the word-wrapping and word-breaking options for the rich edit control. This message is available only in Asianlanguage versions of the operating system.
70
StopGroupTyping
Stops the control from collecting additional typing actions into the current undo action. The control stores the next typing action, if any, into a new action in the undo queue.
71
StreamIn
Inserts text from an input stream into this CRichEditCtrl object
72
StreamOut
Stores text from this CRichEditCtrl object into an output stream.
73
Undo
Reverses the last editing operation.
Message
Map entry
Description
EN_CHANGE
ON_EN_CHANGE( <id>, <memberFxn> )
The user has taken an action that may have altered text in an edit control.
EN_ERRSPACE
ON_EN_ERRSPACE( <id>, <memberFxn> )
The edit control cannot allocate enough memory to meet a specific request.
EN_HSCROLL
ON_EN_HSCROLL( <id>, <memberFxn> )
The user clicks an edit control's horizontal scroll bar. The parent window is notified before the screen is updated.
EN_KILLFOCUS
ON_EN_KILLFOCUS( <id>, <memberFxn> )
The edit control loses the input focus.
MAXTEXT
ON_MAXTEXT( <id>, <memberFxn> )
The current insertion has exceeded the specified number of characters for the edit control and has been truncated.
EN_SETFOCUS
ON_EN_SETFOCUS( <id>, <memberFxn> )
Sent when an edit control receives the input focus.
EN_UPDATE
ON_EN_UPDATE( <id>, <memberFxn> )
he edit control is about to display altered text. Sent after the control has formatted the text but before it screens the text so that the window size can be altered, if necessary.
EN_VSCROLL
ON_EN_VSCROLL( <id>, <memberFxn> )
The user clicks an edit control's vertical scroll bar. The parent window is notified before the screen is updated.
Let us into a simple example by creating a new MFC dialog based application.
Step 1 − Delete the TODO line and drag one Rich Edit Control and three buttons from the Toolbox.
Step 2 − Change the Caption of these three buttons from Bold, Italic and Under Line to IDC_BUTTON_BOLD, IDC_BUTTON_ITALIC and IDC_BUTTON_UNDERLINE respectively.
Step 3 − Set the following properties to True: Multiline, Want Return, Vertical Scroll.
Step 4 − Add the control variable m_richEdit for Rich Edit Control.
Step 5 − Go to the CMFCRichEditApp and call the ::AfxInitRichEdit2() in CMFCRichEditApp::InitInstance() function as shown in the following code.
BOOL CMFCRichEditApp::InitInstance() {
//TODO: call AfxInitRichEdit2() to initialize richedit2 library.
// InitCommonControlsEx() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
::AfxInitRichEdit2();
CWinApp::InitInstance();
AfxEnableControlContainer();
// Create the shell manager, in case the dialog contains
// any shell tree view or shell list view controls.
CShellManager *pShellManager = new CShellManager;
// Activate "Windows Native" visual manager for enabling themes in MFC controls
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need
// Change the registry key under which our settings are stored
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
CMFCRichEditDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK) {
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}else if (nResponse == IDCANCEL) {
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}else if (nResponse == -1) {
TRACE(traceAppMsg, 0, "Warning: dialog creation failed, so
application is terminating unexpectedly.\n");
TRACE(traceAppMsg, 0, "Warning: if you are using MFC controls on
the dialog, you cannot #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.\n");
}
// Delete the shell manager created above.
if (pShellManager != NULL) {
delete pShellManager;
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
Step 6 − Add the Click event handler for all the three buttons. Here is the implementation for these events.
void CMFCRichEditDlg::OnBnClickedButtonBold() {
// TODO: Add your control notification handler code here
CHARFORMAT Cfm;
m_richEdit.GetSelectionCharFormat(Cfm);
Cfm.cbSize = sizeof(CHARFORMAT);
Cfm.dwMask = CFM_BOLD;
Cfm.dwEffects ^= CFE_BOLD;
m_richEdit.SetSelectionCharFormat(Cfm);
m_richEdit.SetFocus();
}
void CMFCRichEditDlg::OnBnClickedButtonItalic() {
// TODO: Add your control notification handler code here
CHARFORMAT Cfm;
m_richEdit.GetSelectionCharFormat(Cfm);
Cfm.cbSize = sizeof(CHARFORMAT);
Cfm.dwMask = CFM_ITALIC;
Cfm.dwEffects ^= CFE_ITALIC;
m_richEdit.SetSelectionCharFormat(Cfm);
m_richEdit.SetFocus();
}
void CMFCRichEditDlg::OnBnClickedButtonUnderline() {
// TODO: Add your control notification handler code here
CHARFORMAT Cfm;
m_richEdit.GetSelectionCharFormat(Cfm);
Cfm.cbSize = sizeof(CHARFORMAT);
Cfm.dwMask = CFM_UNDERLINE;
Cfm.dwEffects ^= CFE_UNDERLINE;
m_richEdit.SetSelectionCharFormat(Cfm);
m_richEdit.SetFocus();
}
Step 7 − When the above code is compiled and executed, you will see the following output. Now enter text and change its formatting by selecting the text and then click on any of the three buttons.
To Continue Learning Please Login
Login with Google