Mfc Rich Edit Control Mfc
- MFC Tutorial
- MFC Useful Resources
Jul 16, 2006 I have created a CEdit control and a CTreeCtrl control, both of which I need to detect key presses so that I can determine when the 'Enter' key is pressed. When it detects that the 'Enter' or 'Return' key has been pressed, I call CRichEditCtrl::SetFocus on my rich edit control.
- Selected Reading
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 | Free download wechat for sony ericsson vivaz u5. 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.
Step 6 − Add the Click event handler for all the three buttons. Here is the implementation for these events.
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.
- MFC Tutorial
- MFC Useful Resources
- Selected Reading
Windows controls are objects that users can interact with to enter or manipulate data. They commonly appear in dialog boxes or on toolbars. There are various types of controls −
A text based control which is used to display text to the user or request text from the user.
A list based control displays a list of items.
A progress based control is used to show the progress of an action.
A static control can be used to show colors, a picture or something that does not regularly fit in the above categories.
Sr.No. | Controls & Description |
---|---|
1 | Static Control A static control is an object that displays information to the user without his or her direct intervention. It can be used to show colors, a geometric shape, or a picture such as an icon, a bitmap, or an animation. |
2 | Animation Control An animation control is a window that displays an Audio clip in AVI format. An AVI clip is a series of bitmap frames, like a movie. Animation controls can only play simple AVI clips, and they do not support sound. It is represented by the CAnimateCtrl class. |
3 | Button A button is an object that the user clicks to initiate an action. Button control is represented by CButton class. |
4 | Bitmap Button A bitmap button displays a picture or a picture and text on its face. This is usually intended to make the button a little explicit. A bitmap button is created using the CBitmapButton class, which is derived from CButton. |
5 | Command Button A command button is an enhanced version of the regular button. It displays a green arrow icon on the left, followed by a caption in regular size. Under the main caption, it can display another smaller caption that serves as a hint to provide more information. |
6 | Static Text A static control displays a text string, box, rectangle, icon, cursor, bitmap, or enhanced metafile. It is represented by CStatic class. It can be used to label, box, or separateother controls. A static control normally takes no input and provides no output. |
7 | List Box A list box displays a list of items, such as filenames, that the user can view and select. A List box is represented by CListBox class. In a single-selection list box, the user can select only one item. In a multiple-selection list box, a range of items can be selected. When the user selects an item, it is highlighted and the list box sends a notification message to the parent window. |
8 | Combo Boxes A combo box consists of a list box combined with either a static control or edit control. it is represented by CComboBox class. The list-box portion of the control may be displayed at all times or may only drop down when the user selects the drop-down arrow next to the control. |
9 | Radio Buttons A radio button is a control that appears as a dot surrounded by a round box. In reality, a radio button is accompanied by one or more other radio buttons that appear and behave as a group. |
10 | Checkboxes A checkbox is a Windows control that allows the user to set or change the value of an item as true or false. |
11 | Image Lists An Image List is a collection of same-sized images, each of which can be referred to by its zero-based index. Image lists are used to efficiently manage large sets of icons or bitmaps. Image lists are represented by CImageList class. |
12 | Edit Box An Edit Box is a rectangular child window in which the user can enter text. It is represented by CEdit class. |
13 | Rich Edit 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. |
14 | Group Box A group box is a static control used to set a visible or programmatic group of controls. The control is a rectangle that groups other controls together. |
15 | Spin Button A Spin Button Control (also known as an up-down control) is a pair of arrow buttons that the user can click to increment or decrement a value, such as a scroll position or a number displayed in a companion control. it is represented by CSpinButtonCtrl class. |
16 | Managing the Updown Control It manages the Updown Controls. |
17 | Progress Control A progress bar control is a window that an application can use to indicate the progress of a lengthy operation. It consists of a rectangle that is gradually filled, from left to right, with the system highlight color as an operation progresses. It is represented by CProgressCtrl class. |
18 | Progress Bars A progress bars is a window that an application can use to indicate the progress of a operation. |
19 | Timer A timer is a non-spatial object that uses recurring lapses of time from a computer or fromyour application. To work, every lapse of period, the control sends a message to the operating system. Unlike most other controls, the MFC timer has neither a button to represent it nor a class. To create a timer, you simply call the CWnd::SetTimer() method. This function call creates a timer for your application. Like the other controls, a timer uses an identifier. |
20 | Date & Time Picker The date and time picker control (CDateTimeCtrl) implements an intuitive and recognizable method of entering or selecting a specific date. The main interface of the control is similar in functionality to a combo box. However, if the user expands the control, a month calendar control appears (by default), allowing the user to specify a particular date. When a date is chosen, the month calendar control automatically disappears. |
21 | Picture If you need to display a picture for your application, Visual C++ provides a special control for that purpose. |
22 | Image Editor The Image editor has an extensive set of tools for creating and editing images, as wellas features to help you create toolbar bitmaps. In addition to bitmaps, icons, and cursors, you can edit images in GIF or JPEG format using commands on the Image menu and tools on the Image Editor Toolbar. |
23 | Slider Controls A Slider Control (also known as a trackbar) is a window containing a slider and optional tick marks. When the user moves the slider, using either the mouse or the direction keys, the control sends notification messages to indicate the change. There are two types of sliders − horizontal and vertical. It is represented by CSliderCtrl class. |
24 | Scrollbars A scrollbar is a graphical control element with which continuous text, pictures or anything else can be scrolled in two directions along a control by clicking an arrow. This control can assume one of two directions − horizontal or vertical. It is represented by CScrollBar class. |
25 | Tree Control A Tree View Control is a window that displays a hierarchical list of items, such as the headings in a document, the entries in an index, or the files and directories on a disk. Each item consists of a label and an optional bitmapped image, and each item can have a list of subitems associated with it. By clicking an item, the user can expand and collapse the associated list of subitems. It is represented by CTreeCtrl class. |
26 | List Control Encapsulates the functionality of a List View Control, which displays a collection of items each consisting of an icon (from an image list) and a label. It is represented by CListCtrl class. A list control consists of using one of four views to display a list of items. |