4

在 2015 年的博客文章RichEdit Colors,微软开发人员Murray Sargent指出,RichEdit控件支持“临时”格式;拼写检查器和 IME 编辑器使用:

临时格式

IME 和校对工具喜欢使用诸如波浪下划线和特殊颜色之类的字符格式来指示专门的文本处理,例如拼写错误。为避免更改底层字符格式,RichEdit 提供了下划线类型和颜色以及前景色和背景色的临时格式。删除此类格式后,将再次使用原始格式进行显示。临时格式不保留在文件格式中,也不能被客户端读出,只能应用。

要定义临时格式属性,请调用

然后根据需要通过调用指定临时格式颜色:

通过调用指定临时下划线颜色和类型ITextFont::SetUnderline(value)

将值指定为value

  • value = tomAutoColor:使用自动颜色(默认文本颜色)。
  • value = (color | 0xFF000000): 临时下划线颜色设置为value & 0x00FFFFFF.
  • 否则,当 value 是有效的下划线类型时:临时下划线类型设置为 value。

要应用如此定义的临时格式,请调用ITextFont->Reset(tomApplyNow). 如果未定义临时格式属性,则使用相应的原始属性。

强调我的

您如何实际删除“临时”格式?

要将临时格式应用于文本块:

ITextRange range = textDocument.Range(0, 5); //startIndex, endIndex
ITextFont font = range.Font();
font.Reset(tomApplyTmp);
font.Underline = tomWave;    //red wavy underline
font.Underline = 0xFF0000FF; //and make the wavy underline red
font.Reset(tomApplyNow);

他在2012 年指出RichEdit 多年来一直支持这些东西 - 文本对象模型(即它是在 Window XP SP1 中引入的):

RichEdit 拼写检查、自动更正和预测

RichEdit 多年来一直支持客户端拼写检查(TOM 对象模型和临时字符格式——请参阅tomApplyTmp)和自动更正(请参阅EM_SETAUTOCORRECTPROC)。但访问拼写检查和自动更正组件是 RichEdit 客户端的责任,内置数学自动更正选项除外。对于像 OneNote 和 Outlook 这样的客户,这样的责任只是应用程序的一小部分。但是对于小程序来说,访问校对组件可能很困难。对于使用Windows RT编写的小型应用程序尤其如此。

我可以弄清楚如何临时格式应用于文本块:

//Get ITextDocument interface for the RichEdit control    
IRichEditOle ole;
SendMessage(RichEdit.Handle, EM_GETOLEINTERFACE, 0, out ole);
ITextDocument doc = ole as ITextDocument;


ITextRange range = doc.Range(spellingError.StartIndex, spellingError.EndIndex);
ITextFont font = range.Font();
font.Reset(tomApplyTmp);
font.Underline = tomWave;
font.Underline = 0xFF0000FF; //and make the wavy underline red
font.Reset(tomApplyNow);

但我不知道如何清除所有现有的临时格式。

我试图“选择一切,什么都不应用”

ITextRange range = doc.Range(0, TextLength); //start index, end index
ITextFont font = range.Font();
font.Reset(tomApplyTmp);
font.Underline = tomNone;
font.Reset(tomApplyNow);

但这只是保留了现有的临时格式。

注: 2015 年 Remy Lebeau( @RemyLebeau ) 指出文本服务对象模型需要 MsftEdit.dll(即 Microsoft Edit v4.1)

奖金喋喋不休

Rich Edit是在 Windows 95 中引入的,最初具有 Windows 类名:

RICHEDIT_CLASS = "RichEdit"

多年来,它得到了改进,但获得了新的类名,位于新的 dll 中,以保持向后兼容性。

Windows XP SP1 引入了新的“Microsoft Edit”类,位于“MsftEdit.dll”中

Version       Dll           Class name const  Class name string             OS
============  ============  ================  ============================  ===========
RichEdit 1.0  Riched32.dll  RICHEDIT_CLASS    "RICHEDIT"                    Windows 95
RichEdit 2.0  Riched20.dll  RICHEDIT_CLASS    "RichEdit20A", "RichEdit20W"  Windows 98
RichEdit 3.0  Riched20.dll  RICHEDIT_CLASS    "RichEdit20A", "RichEdit20W"  Windows 2000   (with RichEdit 1.0 emulator
RichEdit 4.1  Msftedit.dll  MSFTEDIT_CLASS    "RICHEDIT50W"                 Windows XP SP1 (with RichEdit 1.0 emulator)
RichEdit 7.5  MsftEdit.dll  MSFTEDIT_CLASS    "RICHEDIT50W"                 Windows 8
RichEdit 8.5  MsftEdit.dll  MSFTEDIT_CLASS    "RICHEDIT50W"                 Windows 10

因此,“Microsoft Edit”是您应该使用的东西(并且需要用于文本服务),而不是“Rich Edit”。

Microsoft Edit使用较新版本的操作系统进行更新:

Windowx XP:    File description: Rich Text Edit Control, v4.1
Windows Vista: File description: Rich Text Edit Control, v4.1
Windows 7:     File description: Rich Text Edit Control, v4.1
Windows 8:     File description: Rich Text Edit Control, v7.5
Windows 10:    File description: Rich Text Edit Control, v8.5

在 Windows 8 中,Microsoft Edit控件获得了自动支持拼写检查的能力(因为 Windows 8 添加了 SpellCheck API)。

4

1 回答 1

1

那很奇怪。我正在做类似的事情(感谢您的帖子,因为很难找到相关的文档并且以您编写的相同方式重置临时样式没有问题,唯一的区别是我使用 C++:

doc->Range(5, 15, &range);
range->GetFont(&font);
font->Reset(tomApplyTmp);
font->SetUnderline(tomNone);
font->Reset(tomApplyNow);
于 2019-05-09T10:41:06.397 回答