Character Formatting in Rich Edit Controls

Overview

You can use member functions of the rich edit control () to format characters and to retrieve formatting information. For characters, you can specify typeface, size, color, and effects such as bold, italic, and protected.

You can apply character formatting by using the and member functions. To determine the current character formatting for the selected text, use the member function. The structure is used with these member functions to specify character attributes. One of the important members of CHARFORMAT is dwMask. In SetSelectionCharFormat and SetWordCharFormat, dwMask specifies which character attributes will be set by this function call. GetSelectionCharFormat reports the attributes of the first character in the selection; dwMask specifies the attributes that are consistent throughout the selection.

You can also get and set the "default character formatting," 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. To get and set default character formatting, use the and member functions.

The "protected" character attribute does not change the appearance of text. If the user attempts to modify protected text, a rich edit control sends its parent window an EN_PROTECTED notification message, allowing the parent window to allow or prevent the change. To receive this notification message, you must enable it by using the member function. For more information about the event mask, see Notifications from a Rich Edit Control, later in this article.

Foreground color is a character attribute, but background color is a property of the rich edit control. To set the background color, use the member function.

See Also   Windows Common Controls and MFC Classes