RichEdit 8.0 Preview

There’s been a lot of buzz about the Windows 8 Consumer Preview and it is really exciting. One particularly exciting thing missing in the buzz is that Windows 8 contains a new RichEdit! Since the new version is now publically documented on MSDN, I can write about it. I found the public documentation by Binging for ITextRange2, one of the TOM2 interfaces introduced in RichEdit 6.0. As you can imagine, I’ve been dying to write about RichEdit 8 in Windows 8 for quite a while. There’s so much to say that there will be several posts on it.

In contrast, Windows 7 has RichEdit 4.1 which shipped with Windows XP SP1 back in 2003 (the Windows 7 version does have a few upgrades for new languages and security improvements). The new RichEdit is housed in the msftedit.dll. The older RichEdit 3.0 (riched20.dll) that also ships with Windows 8 is the same as that for previous versions of Windows aside from possible security fixes. We keep that riched20.dll around so that we don’t break really old applications that depend on it.

For developers, having the documentation for the TOM2 text object model, up-to-date messages, and the brand new WinRT text object model should be very useful. In previous posts I’ve described features added to RichEdit version 5 through 7 for Microsoft Office and people have commented that it’s kind of disheartening to read about these cool features and not be able to use them for lack of documentation. Well now they’re documented and all you need is Windows 8 to use them.

There are two key differences between the TOM2 interfaces that ship with RichEdit 8 and those in RichEdit 6 and 7: 1) ITextDocument2 is somewhat different and 2) ITextRange2::InsertImage() is new and is accessed through the last entry in the interface table. These changes might complicate things a bit if you want to use the TOM2 documentation with the Office 2007 or 2010 RichEdit. The RichEdit that ships with the next version of Office will have the same TOM2 interfaces as the Windows 8 RichEdit.

The other thing I’d like to point out in this post is that the new RichEdit supports math editing and display! This capability is disabled by default; to enable it, send a message EM_SETEDITSTYLEEX with wparam = 0 and lparam = SES_EX_NOMATH (defined in the new richedit.h). The new RichEdit doesn’t support the math paragraph. There was only so much we could get in. You can paste math text from Word into RichEdit 8 and vice versa since both programs support Math RTF. They also both support MathML and OMML

If you’re programmatically oriented, you might want to check out ITextRange2::BuildUpMath(). This function can do many math text manipulations, most notably the one converting the math linear format into the built-up (Professional) format. The exported math functions MathBuildUp and MathBuildDown can be used by any application that implements the requisite callback interfaces. Word, PowerPoint, and RichEdit itself call these functions to build math up and down, respectively.

If you find problems with RichEdit 8 or with the documentation, please let me know. More posts to come, e.g., on the nested table model, DWrite/D2D operation, native spell checking and autocorrect, touch, native image support, accessibility …! This is the biggest RichEdit upgrade ever.

Comments (14)

  1. Lionel says:

    Wow!  That's nice!

  2. That's really great!

    Murray, could you please explain how to use ITextDocument2 if QueryInterface returns E_NOINTERFACE. I have the latest tom.h from the Visual Studio 11 Beta package, the GUID seems to be correct. I think that the interface is not registered in my system (Win Vista). How can I register TOM2 interfaces? And what operating system can I have except Windows 8?

    Thank you very much!

  3. Nali says:

    It is very interesting.

    Will this upgrade of Richedit impact somehow the Wordpad in Windows 8? E.g. the extension of Wordpad features?

  4. Dear Murray,

    Is there any way to get ITextDocument2 interface in Windows prior to Windows 8? This interface is not registered but the library riched20.dll shipped with MS Office contains it. I load this library, then I create RichEdit60W window and obtain IRichEditOle interface via EM_GETOLEINTERFACE message. But querying for interface ITextDocument2 fails.

    Now I use headers and documentation of TOM2. Unfortunately, your detailed blog "RichEdit Versions 1.0 through 3.0" covers only 1st version of TOM interfaces. As I discovered recently, riched20.dll from Office is a COM type library, and in Windows prior to 8 it's not registered. Unfortunately I haven't enough knowledge and experience in COM programming to obtain ITextDocument2, ITextRange2 interfaces directly from this dll. Could you help me or just direct to the solution of my problem. It is exactly the case when I want to use "TOM2 documentation with the Office 2007 or 2010 RichEdit".

    I would be glad to any way of using ITextDocument2 (in windowed/windowless RichEdit control) in Windows Vista/ Windows 7 since Windows 8 is not finally released yet.

    Thank you and sorry for (maybe) annoying questions.

    This information is very important for me and others, I suppose.

  5. Dear Murray,

    I solved my previous problem (used correct GUIDs exported by the dll), everything was ok, but  I've discovered recently a bug or a very special feature in TOM2. Since I don't know official address of bugtracker or specialized forum, I'm writing you here. So, below is the problem.

    I'm writing a Unicode compiler with math input and use riched20.dll from Microsoft Mathematics program. This dll has version 14.0.4750.0 and seems to be very close or identical with the dll from MS Office 2010. Version 3 math editing is supported. I need to get math plain text from the RichEdit 6.0 control window without visual builddown of mathematical text in that window.

    For this reason I call the TOM2 method ITextRange2::GetText2 with some values of the "Flags" parameter.

    And then I get strange or incorrect behavior.

    For older dll from MS Office 2007 with version 12.0.6606.0 the value Flags=tomNoMathZoneBrackets doesn't remove the math brackets. But it's not so bad. For newer dll 14.0.4750.0 everything works fine with and without Flags=tomNoMathZoneBrackets for most expressions. But for both dlls – 12.0.6606.0 and 14.0.4750.0 – a problem occurs with expressions which include options like box(24&a). The function GetStoryLength for this text range returns 5. It seems that it counts all symbols except 24&, counting 2 surrogates of "a" correctly. And consequently the function ITextRange2::GetText2 places zero symbol after 5 characters and the result is incorrect: □(24&

    It seems to be a bug N1. Was it fixed for next version dlls?

    I tried various values of Flags argument and discovered (without understanding) that the value Flags=tomNoMathZoneBrackets | tomIncludeNumbering fixes the problem. But in this case another serious problem arises: if the text range ends with a carriage return L'r' symbol (when I simply hit Enter), then the whole program hangs in function ITextRange2::GetText2.

    It seems to be a bug N2 (maybe connected with the previous one).

    I would be very glad and happy if the whole math editing system will run like clockwork on Windows 8. And that's why I'm writing you about the problems.

  6. Nali says:

    What version of RichEdit is shipped with Office 2013 Consumer Preview? Is it also RichEdit 8?

    Thank you.

  7. wrx says:

    SendMessage(hWnd,EM_SETEDITSTYLEEX,0,SES_EX_NOMATH ) does not work in Windows8 RTM.

    Is there other way to enable math for RichEdit?

  8. Ivan Manuylovich says:

    Dear Murray,

    Thank you for your posts. I have the same problem with SendMessage(hWnd,EM_SETEDITSTYLEEX,0,SES_EX_NOMATH ). I'm using Windows 8 and msftedit.dll is loaded, but SES_EX_NOMATH does not change. The other flags can be changed, but this one – no. May be we must do something else before this step to allow entering a math zone?


    Ivan Manuylovich

  9. MurrayS3 says:

    Unfortunately math is disabled in the Windows 8 RichEdit. The Windows team didn't have enough time to test it, although it has been tested thoroughly by the RichEdit team. So the SES_EX_NOMATH option does nothing.

  10. MurrayS3 says:

    Re Ivan's question about ITextRange2::GetText2 and ITextRange2::GetStoryLength, the plain-text string returned by GetText2 has a different number of characters in it than the in-memory representation. The latter has for box(24&a) the math-object start delimiter (0xFDD0), the math italic a (0x1D44E–a surrogate pair), the math-object end delimiter (0xFDDF), and the final CR (0x000D). This gives 5 16-bit characters, which is a different count than the linear-format version box(24&a) has. If you call ITextRange::GetText(), you'll get the in-memory version.

  11. Ivan Manuylovich says:

    Thank you for your answer. It's a pity! Do we have a hope that Windows 8.1 will allow math editing in RichEdit? Especially because everything is contained in msftedit.dll and even we can see documentation in MSDN. And also Visual Studio 2013 Preview defines a flag SES_EX_NOMATH.


    Ivan Manuylovich

  12. MurrayS3 says:

    It won't be in Windows 8.1, but hopefully soon thereafter. Thanks for your feedback. It helps us in setting priorities.

  13. Ivan Manuylovich says:

    Thanks. Unfortunately, I'm still searching for decision or workaround to use any RichEdit >=6.0 control in my application. Ok, I'll wait and think.

  14. Liang Yi says:

    Can’t find rich edit 8 in win 10, RICHEDIT60W in win 10 failed, and can’t use BuildUpMath
    Succeed with office 2013 RICHED20.DLL.

    Anyway to use BuildUpMath in win7 and higher OS without office?

Skip to main content