Visual C++ and MFC Fundamentals Chapter 17: Track-Based Controls
Although a rich edit control can be used as a single-line text object, to make it more
efficient, you should make it use various lines. This can be taken care of by setting the
Multiline property to True or adding the ES_MULTILINE style. An example would be:
DWORD RichStyle = WS_CHILD | WS_VISIBLE | ES_MULTILNE;
Once a rich edit can display multiple lines of text, if the text is longer than the control can
display, you should equip it with scroll bars. The vertical scroll bar is made available by
adding checking the Vertical Scroll check box or setting it to True. This can be done
programmatically by adding the WS_VSCROLL window style. Here is an example:
DWORD RichStyle = WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILNE;
The horizontal scroll bar is made possible by setting the Horizontal Scroll property to
True. To do this programmatically, add the WS_HSCROLL window style.
If you do not want the user to change the text in the rich edit control, you can set the
Read-Only property to True. This can also be done by adding the ES_READONLY style.
The rect argument specifies the location and dimensions of the control.
The pParentWnd argument is the control that is hosting the rich edit control. It is usually
a form or a dialog box.
The nID is an identifier for the rich edit control.
Practical Learning: Creating a Rich Edit Application
- Create a Dialog Based Application Type project named Richer and based on
CformView - Delete the TODO line and the OK button
- Change the caption of the Cancel button to Close
- On the Control toolbox, click the Rich Edit button and draw a rectangle from the left
border to the left of the Cancel - On the Properties window, change its ID to IDC_RICHER
- Set the following properties to True: Multiline, Want Return, Vertical Scroll