4 out of 22 rated this helpful - Rate this topic

Using Rich Edit Controls

This section contains topics that demonstrate how to create and use rich edit controls.

In this section

TopicDescription

How to Create Rich Edit Controls

To create a rich edit control, call the CreateWindowEx function, specifying the rich edit window class. For Microsoft Rich Edit 4.1 (Msftedit.dll), specify MSFTEDIT_CLASS as the window class. For all previous versions, specify RICHEDIT_CLASS. For more information, see Versions of Rich Edit.

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. For more information, see Rich Edit Control Styles.

How to Format Text in Rich Edit Controls

An application can send messages to a rich edit control in order to format characters and paragraphs and 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.

How to Interact with the Current Selection

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.

How to Use Rich Edit Text Operations

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.

How to Use Word and Line Break Information

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.

How to Use Rich Edit Clipboard Operations

An application can paste the contents of the clipboard into a rich edit control by 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.

How to Use Streams

You can use streams to transfer data into or out of a rich edit control. A stream is defined by an EDITSTREAM structure, which specifies a buffer and an application-defined callback function.

How to Automatically Resize Rich Edit Controls

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 EN_REQUESTRESIZE notification code whenever the size of the control's content changes.

How to Use Rich Edit Control Notification Codes

A rich edit control's parent window can process notification codes to monitor events that affect the control. Rich edit controls support all of the notification codes that are used with edit controls, as well as several additional ones.

How to Use Font Binding in Rich Edit Controls

Microsoft Rich Edit 3.0 assigns a character set to plain-text characters depending on their context. Some examples are:

  • Greek characters are assigned GREEK_CHARSET.
  • Hangul symbols are assigned HANGUL_CHARSET.
  • Chinese characters are assigned SHIFTJIS_CHARSET if kana characters are found nearby, or GB2312_CHARSET if no kana are found nearby.
  • Non-neutral ANSI characters are assigned ANSI_CHARSET in any event.

How to Use OLE in Rich Edit Controls

This section contains information about using object linking and embedding (OLE) in rich edit controls.

How to Print the Contents of Rich Edit Controls

This section contains information about how to print the contents of rich edit controls.

 

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
How to instantiate Rich Edit 4.1 controls using MSFTEDIT_CLASS

As of March 2, 2008, the above documentation does not explain properly how to instantiate a Rich Edit 4.1 class using MSFTEDIT_CLASS. It only mentions using RICHEDIT_CLASS which only works for Rich Edit controls 3.0 and below. If you want your Rich Edit control to support fully the new Text Services Framework (input from speech recognition, etc.) you'll need to use a Rich Edit 4.1 control. Looking inside Richedit.h in the Platform SDK, one finds the following little tidbit:

#define MSFTEDIT_CLASS  L"RICHEDIT50W"
// NOTE: MSFTEDIT.DLL only registers MSFTEDIT_CLASS. If an application wants
// to use the following Richedit classes, it needs to load the riched20.dll.
// Otherwise, CreateWindow with RICHEDIT_CLASS would fail.
// This also applies to any dialog that uses RICHEDIT_CLASS, [sic]


Some code to illustrate creating a rich edit control depending on what is available (not intended for production use):

#include <Richedit.h>  // #defines MSFTEDIT_CLASS and RICHEDIT_CLASS
  
HWND CreateRichEditControl() {
  static HMODULE msft_mod = LoadLibrary("Msftedit.dll");
  if (msft_mod) {
    // Create a Rich Edit 4.1 control (requires Windows XP SP1 or later)
    return CreateWindowEx(exstyle, MSFTEDIT_CLASS, ...);
  }
  static HMODULE riched_mod = LoadLibrary("Riched20.dll");
  if (riched_mod) {
// Create a Rich Edit 2.0 (98/NT4) or 3.0 (Me/2K/XP) control.
    return CreateWindowEx(exstyle, RICHEDIT_CLASS, ...);
}
  // No suitable DLL found... time to upgrade Windows.
  return NULL;
}


The Platform SDK documentation doesn't seem to make any mention of MSFTEDIT_CLASS; the only place I found it mentioned on MSDN was this TSF blog post:

http://blogs.msdn.com/tsfaware/archive/2007/06/14/how-do-i-use-richedit-4-1.aspx

[ Good feedback, thanks. We'll add this info in the next update to "About Rich Edit Controls." -- Peter Donnelly MSFT ]