The original specification for rich edit controls is Microsoft® Rich Edit 1.0; the current specification is Rich Edit 4.1. Each version of rich edit is a superset of the preceding one, except that only Asian builds of Rich Edit 1.0 have a vertical text option.
To create a rich edit control, call the
Rich edit controls support most of the window styles used with edit controls as well as additional styles. You should specify the ES_MULTILINE window style if you want to allow more than one line of text in the control.
An application can send messages to a rich edit control to format characters and paragraphs to retrieve formatting information. Paragraph formatting attributes include alignment, tabs, indents, numbering, and simple tables. For characters, you can specify font name, size, color, and effects such as bold, italic, and protected.
You can apply paragraph formatting by using the EM_SETPARAFORMAT
message. To determine the current paragraph formatting for the selected text,
use the
You can apply character formatting by using the
You can also use EM_SETCHARFORMAT and EM_GETCHARFORMAT messages to set and retrieve the character formatting of the insertion point, which is the formatting applied to any subsequently inserted characters. For example, if an application sets the default character formatting to bold and the user then types a character, that character is bold.
The character formatting of the insertion point is applied to newly inserted text only if the current selection is empty (if the current selection is an insertion point). Otherwise, the new text assumes the character formatting of the text it replaces. If the selection changes, the default character formatting changes to match the first character in the new selection.
The protected character effect is unique in that it does not change the
appearance of text. If the user attempts to modify protected text, a rich edit
control sends its parent window an
Foreground color is always a character attribute. In Rich Edit 1.0,
background color is only a property of the rich edit control. To set the default
background color, use the
The user can select text in a rich edit control by using the mouse or the keyboard. The current selection is the range of selected characters, or the position of the insertion point if no characters are selected. An application can get information about the current selection, set it, determine when it changes, and show or hide the selection highlight.
To determine the current selection in a rich edit control, use the
An application can detect when the current selection changes by processing
the
By default, a rich edit control shows and hides the selection highlight when
it gains and loses the focus. You can show or hide the selection highlight at
any time by using the
As with edit controls, you can specify the ES_NOHIDESEL window style to prevent a rich edit control from hiding the selection highlight when it loses the focus.
As an alternative to using the EM_EXGETSEL and EM_EXSETSEL
messages, you can retrieve and set the current selection by using the
An application can send messages to retrieve or find text in a rich edit control. You can retrieve either the selected text or a specified range of text.
To get the selected text in a rich edit control, use the
To retrieve a specified range of text, use the
You can search for a string in a rich edit control by using the
Rich Edit 3.0 also supports the HexToUnicode IME, which allows a user to
convert between hexadecimal and Unicode by using hot keys. For more information,
see
A rich edit control calls a function called a word-break procedure to find breaks between words and to determine where it can break lines. The control uses this information when performing word-wrap operations and when processing CTRL+LEFT ARROW key and CTRL+RIGHT ARROW key combinations. An application can send messages to a rich edit control to replace the default word-break procedure, to retrieve word-break information, and to determine what line a given character falls on.
Word-break procedures for rich edit controls are similar to those for edit controls, but they have additional capabilities: word-break procedures for both kinds of controls can determine whether a character is a delimiter and can find the nearest word break before or after the specified position. A delimiter is a character that marks the end of a word, such as a space. Usually, in an edit control, a word break occurs only after delimiters. However, different rules apply to most Asian languages.
Word-break procedures for rich edit controls also group characters into character classes, each identified by a value in the range 0x00 through 0x0F. Breaks occur either after delimiters or between characters of different classes. Thus, a word-break procedure with different classes for alphanumeric and punctuation characters would find two word breaks in the string "Win.doc" (before and after the period).
A character's class can be combined with zero or more word-break flags to form an 8-bit value. When performing word-wrap operations, a rich edit control uses word-break flags to determine where it can break lines. Rich Edit uses the following word-break flags.
| Flags | Description |
|---|---|
| WBF_BREAKAFTER | Lines may be broken after the character. |
| WBF_BREAKLINE | The character is a delimiter. Delimiters mark the ends of words. Lines may be broken after delimiters. |
| WBF_ISWHITE | The character is a white-space character. Trailing white-space characters are not included in the length of a line when wrapping. |
The WBF_BREAKAFTER value is used to allow wrapping after a character that does not mark the end of a word, such as a hyphen.
You can replace the default word-break procedure for a rich edit control,
with your own procedure by using the
For Rich Edit 1.0, you can use the
You can use the
To determine which line a given character falls on, you can use the
An application can paste the contents of the clipboard into a rich edit control using either the best available clipboard format or a specific clipboard format. You can also determine whether a rich edit control is capable of pasting a clipboard format.
As with an edit control, you can copy or cut the contents of the current
selection by using the
To paste a specific clipboard format, you can use the
You can also use the EM_CANPASTE message to determine whether any
available clipboard format is recognized by a rich edit control. This message is
useful when processing the
Rich edit controls register two clipboard formats:
An application can register these formats by using the
You can use streams to transfer data into or out of a rich edit control. A
stream is defined by an
To read data into a rich edit control (that is, stream in the data), use the
To save the contents of a rich edit control (that is, stream out the data),
you can use the
You can send messages to a rich edit control to render its output for a specified device, such as a printer. You can also specify the output device for which a rich edit control formats its text.
To format part of a rich edit control's contents for a specific device, you
can use the
After formatting text for an output device, you can send the output to the
device by using the
You can use the
An application can resize a rich edit control as needed so that it is always
the same size as its contents. A rich edit control supports this so-called
bottomless functionality by sending its parent window an
When processing the EN_REQUESTRESIZE notification message, an
application should resize the control to the dimensions in the specified
You can force a bottomless rich edit control to send an EN_REQUESTRESIZE
notification message by using the
To receive EN_REQUESTRESIZE notification messages, you must enable the notification by using the EM_SETEVENTMASK message.
A rich edit control's parent window can process notification messages to monitor events affecting the control. Rich edit controls support all of the notification messages used with edit controls as well as several additional ones. You can determine which notification messages a rich edit control sends its parent window by setting its event mask.
To set the event mask for a rich edit control, use the EM_SETEVENTMASK
message. You can retrieve the current event mask for a rich edit control by
using the
A rich edit control's parent window can filter all keyboard and mouse input
to the control by processing the
An application can process the EN_PROTECTED notification message to detect when the user attempts to modify protected text. To mark a range of text as protected, you can set the protected character effect. For more information, see Text Formatting.
You can enable the user to drop files in a rich edit control by processing
the
Rich Edit 3.0 will assign a charset to plain-text characters depending on their context. Some examples are:
Neutral characters like blanks and digits are assigned a charset depending on their context. For example, a blank surrounded by characters of the same charset gets that charset. Neutrals and digits used for bidirectional text are assigned charsets in a way based on the Unicode bidirectional algorithm.
Once charsets are assigned, Rich Edit scans the text around the insertion point forward and backward to find the nearest fonts that have been used for the charsets. If no font is found for a charset, rich edit uses the font chosen by the client for that charset. If the client hasn't specified a font for the charset, rich edit uses the default font for that charset. If the client wants some other font, the client can always change it, but this approach will work most of the time. The current default font choices are based on the following table. Note that the default fonts are set per-process, and there are separate lists for UI usage and for non-UI usage.
| Language | UI font name | UI font size | non-UI font name | non-UI font size |
|---|---|---|---|---|
| Western, CE, ME, Vietnamese | Tahoma | 8 | Arial | 10 |
| Japanese | MS UI Gothic | 9 | MS P Gothic | 10 |
| Korean | Gulim | 9 | Gulim | 9 |
| Simplified Chinese | Simsun | 9 | SimSun | 10 |
| Traditional Chinese | PMingLiU | 9 | PMingLiU | 9 |
| Thai | MS Sans Serif | 8 | Tahoma | 14 |
| Symbols | Wingdings | 8 | Wingdings | 10 |
| Devanagari | Mangal | 8 | Mangal | 10 |
| Tamil | Latha | 8 | Latha | 10 |
| Georgian, Armenian | Arial Unicode | 8 | Arial Unicode | 10 |
Therefore, in the default font-binding table (entries have charset, font name, size), Rich Edit allows ANSI_CHARSET to match several charsets, while the appropriate charset matches other fonts on a one-to-one basis. More precisely, rich edit uses the ANSI_CHARSET choice whenever no other alternative is found. You will be able to specify a finer granularity than this, for example: assign a specific ARABIC_CHARSET for Arabic runs, a specific Greek font for Greek runs, for example. This finer granularity will also be used if a font with the desired charset stamp is found somewhere in the document before the area being font-bound.
Note that Rich Edit does not currently handle a missing glyph in a font that claims to support a charset but is incomplete. At display time in a complex script, Rich Edit does end up knowing that such a glyph is missing, but it does not cause the backing store to use a new font. Normally, the underlying font linking of the OS will accomplish this.
Rich Edit 4.1: To set the default font for a script, call EM_SETCHARFORMAT with CHARFORMAT2, specifying yHeight, bCharSet, bPitchAndFamily, szFaceName, and lcid. Also, to get the default font for a specific code page, call EM_GETCHARFORMAT with CHARFORMAT2 specifying bCharSet and lcid.
Rich edit controls support most but not all functionality for multiline edit controls. This section lists the edit control messages and window styles that are not supported by rich edit controls.
The following messages are processed by edit controls but not by rich edit controls.
| Unsupported message | Comments |
|---|---|
| Not supported. | |
| Rich edit controls do not store text as a simple array of characters. | |
| Not supported. | |
| Not supported. | |
| Rich edit controls do not store text as a simple array of characters. | |
| Not supported. | |
| Supported in Rich Edit 3.0. | |
| Not supported. | |
| The EM_SETPARAFORMAT message is used instead.
Supported in Rich Edit 3.0.
|
|
| WM_CTLCOLOR | The EM_SETBKGNDCOLOR message is used instead. |
| The EM_GETCHARFORMAT message is used instead. |
The following window styles are used with multiline edit controls but not with rich edit controls: ES_LOWERCASE, ES_UPPERCASE, and ES_OEMCONVERT.
Rich edit controls support the following shortcut keys.
| Keys | Operations | Comments |
|---|---|---|
| Shift+Backspace | Generate a LRM/LRM on a bidi keyboard | BiDi specific |
| Ctrl+Tab | Tab | |
| Ctrl+Clear | Select all | |
| Ctrl+Number Pad 5 | Select all | |
| Ctrl+A | Select all | |
| Ctrl+E | Center alignment | |
| Ctrl+J | Justify alignment | |
| Ctrl+R | Right alignment | |
| Ctrl+L | Left alignment | |
| Ctrl+C | Copy | |
| Ctrl+V | Paste | |
| Ctrl+X | Cut | |
| Ctrl+Z | Undo | |
| Ctrl+Y | Redo | |
| Ctrl+'+' (Ctrl+Shift+'=') | Superscript | |
| Ctrl+'=' | Subscript | |
| Ctrl+1 | Line spacing = 1 line. | |
| Ctrl+2 | Line spacing = 2 lines. | |
| Ctrl+5 | Line spacing = 1.5 lines. | |
| Ctrl+' (apostrophe) | Accent acute | After pressing the short cut key, press the appropriate letter (for example a, e, or u). This applies to English, French, German, Italian, and Spanish keyboards only. |
| Ctrl+` (grave) | Accent grave | See Ctrl+' comments. |
| Ctrl+~ (tilde) | Accent tilde | See Ctrl+' comments. |
| Ctrl+; (semicolon) | Accent umlaut | See Ctrl+' comments. |
| Ctrl+Shift+6 | Accent caret (circumflex) | See Ctrl+' comments. |
| Ctrl+, (comma) | Accent cedilla | See Ctrl+' comments. |
| Ctrl+Shift+' (apostrophe) | Activate smart quotes | |
| Backspace | If text is protected, beep and do not delete it. Otherwise, delete previous character. | |
| Ctrl+Backspace | Delete previous word. This generates a VK_F16 code. | |
| F16 | Same as Backspace. | |
| Ctrl+Insert | Copy | |
| Shift+Insert | Paste | |
| Insert | Overwrite | DBCS does not overwrite. |
| Ctrl+Left Arrow | Move cursor one word to the left. | On bidi keyboard, this depends on the direction of the text. |
| Ctrl+Right Arrow | Move cursor one word to the right. | See Ctrl+Left Arrow comments. |
| Ctrl+Left Shift | Left alignment | In BiDi documents, this is for left-to-right reading order. |
| Ctrl+Right Shift | Right alignment | In BiDi documents, this is for right-to-left reading order. |
| Ctrl+Up Arrow | Move to the line above. | |
| Ctrl+Down Arrow | Move to the line below. | |
| Ctrl+Home | Move to the beginning of the document. | |
| Ctrl+End | Move to the end of the document. | |
| Ctrl+Page Up | Move one page up. | If in SystemEditMode and Single Line control, do nothing. |
| Ctrl+Page Down | Move one page down. | See Ctrl+Page Up comments. |
| Ctrl+Delete | Delete the next word or selected characters. | |
| Shift+Delete | Cut the selected characters. | |
| Esc | Stop drag-drop. | While doing a drag-drop of text. |
| Alt+Esc | Change the active application. | |
| Alt+X | Converts the Unicode hexadecimal value preceding the insertion point to the corresponding Unicode character. | |
| Alt+Shift+X | Converts the Unicode character preceding the insertion point to the corresponding Unicode hexadecimal value. | |
| Alt+0xxx (Number Pad) | Inserts Unicode values if xxx is greater than 255. When xxx is less than 256, ASCI range text is inserted based on the current keyboard. | Must enter decimal values. |
| Alt+Shift+Ctrl+F12 | Hex to Unicode. | In case Alt+X is already taken for another use. |
| Alt+Shift+Ctrl+F11 | Selected text will be output to the debugger window and saved to %temp%\DumpFontInfo.txt. | For Debug only (need to set Flag=8 in Win.ini) |
| Ctrl+Shift+A | Set all caps. | |
| Ctrl+Shift+L | Fiddle bullet style. | |
| Ctrl+Shift+Right Arrow | Increase font size. | Font size changes by 1 point in the range 4pt-11pt; by 2points for 12pt-28pt; it changes from 28pt -> 36pt -> 48pt -> 72pt -> 80pt; it changes by 10 points in the range 80pt - 1630pt; the maximum value is 1638. |
| Ctrl+Shift+Left Arrow | Decrease font size. | See Ctrl+Shift+Right Arrow comments. |