在Richedit中怎么实际URL像Word那样
输入的是一个网站或邮件地址时可以
自己动变成兰色的。当鼠标点那个还可以打开IE。

解决方案 »

  1.   

    TRichEdit实现URL
    Author: Mike Shkolnik 
    {....}   protected 
        procedure WndProc(var Message: TMessage); override; 
         
    {....} 
    uses Richedit, ShellApi; {Today I want to show how to implement URL highlighting and URL navigation 
    without any third-party components. This functionality is implemented in 
    RichEdit from Microsoft (and MS Outlook use this feature, for example) and 
    only Borland's developers didn't publish it for us.} procedure TForm1.FormCreate(Sender: TObject); 
    var 
      mask: Word; 
    begin 
      mask := SendMessage(RichEdit1.Handle, EM_GETEVENTMASK, 0, 0); 
      SendMessage(RichEdit1.Handle, EM_SETEVENTMASK, 0, mask or ENM_LINK); 
      SendMessage(RichEdit1.Handle, EM_AUTOURLDETECT, Integer(True), 0);   //Some text in RichEdit 
      RichEdit1.Text := 'Scalabium Software'#13#10 + 
        ' Site is located at www.scalabium.com. Welcome to our site.'; 
    end; procedure TForm1.WndProc(var Message: TMessage); 
    var 
      p: TENLink; 
      strURL: string; 
    begin 
      if (Message.Msg = WM_NOTIFY) then 
      begin 
        if (PNMHDR(Message.lParam).code = EN_LINK) then 
        begin 
          p := TENLink(Pointer(TWMNotify(Message).NMHdr)^); 
          if (p.Msg = WM_LBUTTONDOWN) then 
          begin 
            SendMessage(RichEdit1.Handle, EM_EXSETSEL, 0, Longint(@(p.chrg))); 
            strURL := RichEdit1.SelText; 
            ShellExecute(Handle, 'open', PChar(strURL), 0, 0, SW_SHOWNORMAL); 
          end 
        end 
      end;   inherited; 
    end; 
      

  2.   

    提示 EM_GETEVENTMASK 没有定义,怎么解决?
      

  3.   

    uses Richedit, ShellApi;
         ~~~~~~~~看东西看三不看四
      

  4.   

    用那个代码的话,如果richedit放到一个Panel上,点击的消息就截获不到了?请问如何解决?
      

  5.   

    用 richediturl 就可以了