Overview of the Technology


  • Text Object Model (TOM) interfaces: A substantial set of text-manipulation interfaces. Text solutions such as Microsoft Word and rich edit controls support the TOM feature set. Since rich edit controls ship with Microsoft Windows operating systems, they are the standard means of obtaining TOM functionality.

Rich Edit is a component that provides a variety of edit functionality in a single, worldwide binary that runs on Microsoft Windows 95/98/Millennium Edition (Me) and on Microsoft Windows NT/2000/XP. The edit controls can be plaintext or rich text, single or multiline, and can support Unicode encodings and standard Windows character sets (125x, Shift-JIS, GB 2312-80, Big-5, Hangul, Thai).

Rich edit controls are windows in which the user can enter, edit, format, print, and save text. The text can be assigned character and paragraph formatting, and can include embedded Component Object Model (COM) objects. Richedit controls support almost all of the messages and notifications used with multiline edit controls. Thus applications that already use edit controls can be easily changed to use rich edit controls. Additional messages and notifications enable applications to access the functionality unique to rich edit controls.

Rich edit controls have a multilevel Undo feature, message and COM interfaces, considerable compatibility with Word, rich character and paragraph properties, a zoom feature, support for Input Method Editors (IMEs), speech and handwriting input, rich complex-script support (for bidirectional languages, Indic languages, Vietnamese, and Thai), pagination, multilevel tables, autocorrection, hyphenation, kerning, and auto-URL detection. Also available within rich edit controls are East Asian features such as vertical text, font binding, and support for Unicode surrogate pairs and most Unicode 3.0 scripts. This chapter will give you a closer look at some of these features and capabilities.

Clients of Rich Edit include Microsoft Office dialog boxes, WordPad, Microsoft Outlook Rich Text Format (RTF) editor, Microsoft Pocket Word, eBooks, Microsoft FrontPage source-view functionality, and Microsoft Visual Basic edit controls. Itself a component, Rich Edit uses other components including Uniscribe (an advanced-typography line-layout component), Microsoft Windows Text Services Framework (TSF), a special input services component, and various callbacks for access to autocorrect, hyphenation, and ClearType libraries. As a result, Rich Edit scales from simple single-line, plaintext controls used in dialog boxes to quite sophisticated rich-text instances with surprisingly high quality typography.

The following demonstrates how to create a rich edit control. It also explains ways to enhance the rich edit control, such as by using certain messages and TOM interfaces.

Creating a Rich Edit Control

The sample code provided in this section offers assistance as you work with Rich Edit to create rich edit controls. Somewhere in your code you need to load the appropriate rich edit library. For Rich Edit 1, use:


For Rich Edit 2, 3, or 4, use:


For Rich Edit 4.x, use:


One way to create a rich edit control is to use the following code:

 HWND CreateRichEditWindow(  HWND hwndParent,  LPRECT prc,  DWORD dwStyles,  DWORD dwExStyles.  BOOL fUnicode,  HINSTANCE hinst) {  if(!dwStyle)  dwStyle = ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE |   ES_NOHIDESEL | ES_SAVESEL | ES_SELECTIONBAR |   WS_CHILD | WS_CLIPCHILDREN | WS_HSCROLL |   WS_VISIBLE | WS_VSCROLL;  HWND hwnd = CreateWindowEx(  dwExStyles,  Unicode ? TEXT("RichEdit20W") : TEXT("RichEdit20A"),   0,  dwStyle,  prc->left,  prc->top,  prc->right - prc->left,  prc->bottom - prc->top,  hwndParent,  0,  hinst,  0);  return hwnd;} 

Note that instead of registering the old windows class names, known as "RichEdit20W" and "RichEdit20A," Rich Edit 4.1 (or Msftedit.dll) uses a new window class called "RichEdit50W." Thus for the previous example, you would use the "RichEdit50W" window class name in the CreateWindowEx call when working with Rich Edit 4.1.

The window styles in Rich Edit are handy but rather limited. To enhance the rich edit control, messages such as EM_SETCHARFORMAT, EM_SETPARA-FORMAT, and TOM interfaces are quite useful. You can also create a rich edit control in windowless mode by executing CreateTextServices(), which is exported by the rich edit dynamic-link library (DLL) and returns a pointer to an ITextServices object.

To use the TOM interfaces-which consist of a set of six Common Object Model dual interfaces-you can get ITextDocument and ITextRange interfaces from a rich edit window at the point pt by using the following code:

 HWND hwnd; ITextDocument *pDoc; ITextRange *pRange; POINT pt; IUnknown *pUnk = NULL; GetCursorPos(&pt); hwnd = WindowFromPoint(pt); SendMessage(hwnd, EM_GETOLEINTERFACE, 0, (LPARAM)&pUnk); if(pUnk &&  pUnk->QueryInterface(IID_ITextDocument, &pDoc) == NOERROR)  {  pDoc->RangeFromPoint(pt.x, pt.y, &pRange);  //  Continue with rest of program.  } 

Indeed, Rich Edit provides versatility and scalability to its many clients. In addition, it is widely available, as you will see in the next section.

Microsoft Corporation - Developing International Software
Developing International Software
ISBN: 0735615837
EAN: 2147483647
Year: 2003
Pages: 198

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net