今天给大家分享的是由图老师小编精心为您推荐的在RichEdit中实现超链接,喜欢的朋友可以分享一下,也算是给小编一份支持,大家都不容易啊!
【 tulaoshi.com - 编程语言 】
首先在Form上放置一个RichEdit。
在窗体的构造函数中添加以下代码:
__fastcall TMainForm::TMainForm(TComponent* Owner)(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)
: TForm(Owner)
{
unsigned mask = SendMessage(RichEdit1-Handle, EM_GETEVENTMASK, 0, 0);
SendMessage(RichEdit1-Handle, EM_SETEVENTMASK, 0, mask | ENM_LINK);
SendMessage(RichEdit1-Handle, EM_AUTOURLDETECT, true, 0); //自动检测URL
RichEdit1-Text = "欢迎访问C++ Buildern"
"网址: http://www.ccrun.comn"
"偶的信箱:n"
"mailto::info@ccrun.com n"
"嘿嘿n";
}
重载窗体的WndProc
1。在.h中添加:
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)protected:
virtual void __fastcall WndProc(Messages::TMessage &Message);
2。在.cpp中添加:
//---------------------------------------------------------------------------
void __fastcall TMainForm::WndProc(Messages::TMessage &Message)
{
if (Message.Msg == WM_NOTIFY)
{
if (((LPNMHDR)Message.LParam)-code == EN_LINK)
{
ENLINK* p = (ENLINK *)Message.LParam;
if (p-msg == WM_LBUTTONDOWN)
{
SendMessage(RichEdit1-Handle, EM_EXSETSEL, 0, (LPARAM)&(p-chrg));
ShellExecute(Handle, "open", RichEdit1-SelText.c_str(), 0, 0, SW_SHOWNORMAL);
}
}
}
TForm::WndProc(Message);
}
以上代码均已测试通过。
来源:http://www.tulaoshi.com/n/20160219/1612479.html
看过《在RichEdit中实现超链接》的人还看了以下文章 更多>>