如何在 RichEdit 控件内查找粗体文本?
显然,我可以使用 EM_GETCHARFORMAT 一次处理一个字符,但速度非常慢。
一种想法是以某种方式使用 ITextDocument/ITextFont 接口,另一种想法是使用 EM_STREAMOUT 消息并手动解析 RTF。但我无法决定哪种方法更好,并且对实现细节非常模糊。将不胜感激任何帮助,谢谢!
I can obviously do it one character at a time using EM_GETCHARFORMAT, but it is extremely slow.
One idea is to somehow use the ITextDocument/ITextFont interfaces, the other is to use the EM_STREAMOUT message and manually parse the RTF. But I can't decide which approach is better and am very fuzzy on the implementation details. Will appreciate any help, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一个令我满意的解决方案,并希望与您分享:
ITextRange
接口包含一个非常有用的方法Expand
,可用于查找常量的连续运行字符 (tomCharFormat
) 和段落 (tomParaFormat
) 格式。这是一些示例代码(警告:代码是概念验证意大利面条,没有任何错误处理,
根据需要应用重构):
I've found a solution that satisfies me and think will share it with you:
The
ITextRange
interface contains a very useful methodExpand
which can be used to find continuous runs of constant character (tomCharFormat
) and paragraph (tomParaFormat
) formatting.Here is some sample code (warning: code is a proof-of-concept spaghetti without any error handling,
apply refactoring as needed):