如何在 RichEdit 2.0 中自动检测 url?
当我们有一个 RichEdit 控件并向其发送一条 WPARAM 设置为 TRUE 的 EM_AUTOURLDETECT
消息时,它会很好地突出显示检测到的 URL 并发送 EN_LINK
通知。 但它仅对输入到控件中的文本执行此操作。 我还没有找到使用 SetWindowText
或 EM_STREAMIN
加载到控件中的文本的方法。 请帮忙! 谢谢
更新: 我从头开始创建了一个测试应用程序,它运行良好。 我认为问题可能是我对控件进行了超类化,即创建了一个新的窗口类并仅使用原始类的窗口过程。 我将尝试对控件进行子类化..
When we have a RichEdit control and send it an EM_AUTOURLDETECT
message with WPARAM set to TRUE, it nicely hightlights the detected URLs and sends the EN_LINK
notifications.
But it does this only for text that is entered into the control. I haven't found the way to do it for text that's loaded into the control with SetWindowText
or EM_STREAMIN
.
Please help! Thanks
Upd:
I've created a test application from scratch and it works fine there. I think the problem might be that I have superclassed the control, that is, created a new window class and just use the window procedure of the original class. I'm gonna try subclassing the control instead..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能只需将文本重写到控件即可重新解析。
You might just have to rewrite the text to the control to get it to re-parse.
在不知道您尝试使用 SetWindowText 和 EM_STREAMIN 添加到控件的文本格式的情况下,我将进行猜测并说这可能与控件的文本模式有关。 设置控件的内容后,尝试向其发送 EM_GETTEXTMODE< /a> 消息并查看 TM_PLAINTEXT 位是否已设置。 如果是这种情况,请尝试发送 EM_SETTEXTMODE 消息后跟 EM_AUTOURLDETECT。 您的代码应该如下所示:
Without knowing the format of the text you are trying to add to the control with SetWindowText and EM_STREAMIN I'm going to take a guess and say this might have something to do with the control's text mode. After setting the contents of the control try sending it a EM_GETTEXTMODE message and see if the TM_PLAINTEXT bit is set. If this is the case then try sending a EM_SETTEXTMODE message followed by EM_AUTOURLDETECT. Your code should look something like this:
我刚刚构建了一个基于 WTL 对话框的基本应用程序,其中包含 riched20 控件,并且以下工作正常:
我有一些旧的 MFC 代码可以执行类似的操作,尽管使用 ES_STREAM,并且它也工作正常。
FWIW WTL
CRichEditCtrl
包装器非常薄。SetAutoURLDetect
只需调用SendMessage
并传递EM_AUTOURLDETECT
即可。我正在将
_RICHEDIT_VER
设置为0x0200
FWIW 进行编译。I just knocked up a basic WTL dialog based app containing a riched20 control and the following works fine:
I have some old MFC code that does something similar, albeit with ES_STREAM, and it works OK too.
FWIW the WTL
CRichEditCtrl
wrapper is pretty thin.SetAutoURLDetect
simply callsSendMessage
passing itEM_AUTOURLDETECT
.I am compiling with
_RICHEDIT_VER
set to0x0200
FWIW.