To implement a hyperlink in RichEdit

Source: Internet
Author: User

First, place a richedit on the form.

Add the following code to the form's constructor:

__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 of overloaded forms

1. Add in. h:

Protected

virtual void __fastcall WndProc (messages::tmessage &message);

2. Add in. 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);
}

The above code has been tested through.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.