<b>在RichEdit中实现超链接</b>[VC/C++编程]
本文“<b>在RichEdit中实现超链接</b>[VC/C++编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
首先在Form上安排一个RichEdit.
在窗体的构造函数中增添以下代码:
__fastcall TMainForm::TMainForm(TComponent* Owner)
: 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++ Builder\n"
"网址: http://www.ccrun.com\n"
"偶的信箱:\n"
"mailto::info@ccrun.com \n"
"嘿嘿\n";
}
重载窗体的WndProc
1.在.h中增添:
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);
}
以上代码均已测试通过.
以上是“<b>在RichEdit中实现超链接</b>[VC/C++编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |