如何自动检测RichEdit 2.0中的网址? [英] How to autodetect urls in RichEdit 2.0?
问题描述
当我们拥有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..
推荐答案
我刚刚打开了一个基于WTL对话框的基本应用程序,其中包含riched20控件,并且可以正常工作:
I just knocked up a basic WTL dialog based app containing a riched20 control and the following works fine:
CRichEditCtrl richedit = GetDlgItem(IDC_RICHEDIT);
richedit.SetAutoURLDetect(TRUE);
richedit.SetWindowText(_T("http://www.stackoverflow.com"));
我有一些旧的MFC代码,尽管使用了ES_STREAM,但它们执行的功能类似,并且也可以正常工作.
I have some old MFC code that does something similar, albeit with ES_STREAM, and it works OK too.
FWIW WTL CRichEditCtrl
包装器非常薄. SetAutoURLDetect
只需调用SendMessage
并将其传递给EM_AUTOURLDETECT
.
FWIW the WTL CRichEditCtrl
wrapper is pretty thin. SetAutoURLDetect
simply calls SendMessage
passing it EM_AUTOURLDETECT
.
我正在将_RICHEDIT_VER
设置为0x0200
FWIW.
I am compiling with _RICHEDIT_VER
set to 0x0200
FWIW.
这篇关于如何自动检测RichEdit 2.0中的网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!