RichEditD2D Window Controls

murrays

This post is for desktop programmers who use RichEdit window controls in their applications and would like to have more display functionality. Examples of such controls include the desktop Outlook To, Cc, and Subject lines as well as WinForms RichTextBox controls, WordPad, and myriad other programs. It’s easy to create a RichEdit window control by calling CreateWindowEx(dwExStyle, lpClassName, …), where lpClassName identifies the class of RichEdit control. Up to January 2020, all RichEdit window controls use the RichEdit GDI/Uniscribe code path. Accordingly, they cannot benefit from the many improvements only available on the RichEdit D2D/DirectWrite path. Such improvements include color-font support, color emoji, OpenType features such as swash variants and stylistic sets, and variable-font axis settings.

In January 2020, the Microsoft 365 RichEdit introduced a D2D/DirectWrite RichEdit window control with the new window class “RichEditD2D”. It uses D2D/DirectWrite for text and images and the window’s HDC for rendering embedded objects. It doesn’t support printing yet, since printing requires GDI. Fortunately, many applications don’t need to print anymore. On my laptop, the Microsoft 365 RichEdit is housed in C:\Program Files\Microsoft Office\root\vfs\ProgramFilesCommonX64\Microsoft Shared\OFFICE16\riched20.dll.

The RichEditD2D window class is implemented using the ID2D1Factory::CreateDCRenderTarget() method to create a highly functional ID2D1RenderTarget for an HDC. Image display doesn’t need an HDC and is rendered correctly on the D2D/DirectWrite path. OLE objects need an HDC and are queued up for rendering after the D2D/DirectWrite rendering finishes. It’s important to support OLE objects partly because the desktop Outlook To and Cc resolved email addresses are OLE objects.

The RichEditD2D window class works well with the Win32 Outlook To, Cc, and subject lines, rendering emoji in color on the subject line. Released versions of Outlook don’t use the RichEditD2D window class, so you’ll still see black and white emoji’s on Outlook’s Subject line ☹. Also, the RichEditD2D implementation hasn’t been ported to Window’s msftedit.dll used by WordPad and other non-Office programs.

RichEdit windowless controls have supported the D2D/DirectWrite code path for years now. For such controls, the client has to implement the ITextHost or ITextHost2 interface, which are more complicated than simply calling CreateWindowEx(). They’re also more flexible, so many programs use windowless RichEdit controls in Office and in Windows. For example, the XAML TextBox and RichTextBox controls use windowless controls running in the D2D/DirectWrite mode.

1 comment

Leave a comment

  • Avatar
    Leonard de Ruijter

    Interesting blog post.
    When I look at the to/ cc and subject fields in Outlook, they still have the RichEdit20WPT window class. Is there any way to test this yet?
    I’m asking as one of the developers of the NVDA screen reader, it would help if NVDA would support this new window class as soon as it will be used more widely.