delphi RichEdit 加入链接


本文整理自网络,侵删。

 

unit Unit1;

interface

uses
windows, messages, sysutils, variants, classes, graphics, controls, forms,

dialogs, stdctrls, comctrls,richedit,shellapi;


type
  TForm1 = class(TForm)
    Button1: TButton;
    RichEdit1: TRichEdit;
    procedure wndproc(var message : tmessage); override;
   procedure  InitRichEditURLDetection(re:TRichEdit);
    procedure Button1Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.InitRichEditURLDetection(re: TRichEdit);
var

mask: Word;

begin

mask := SendMessage(RE.Handle, EM_GETEVENTMASK, 0,0);

SendMessage(RE.Handle, EM_SETEVENTMASK,0, mask or ENM_LINK);

SendMessage(RE.Handle,EM_AUTOURLDETECT, Integer(True), 0);

 


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;

procedure TForm1.Button1Click(Sender: TObject);
 
var
s: string;
begin
InitRichEditURLDetection(RichEdit1);
s:='http://www.180it.com' + #13#10 +
'mailto:haokucn@163.com' + #13#10;

RichEdit1.Text := s;
end;

end.

相关阅读 >>

Delphi for android 获取手机号

Delphi 屏幕截图完美解决方案

Delphi mscomm 实时串口通讯

Delphi编写的android程序获取root权限实现(2015.4.15更新,支持android 4.4)

Delphi 使用钩子函数 - 钩子链和 callnexthookex 的返回值

Delphi 中的md5实现方法及Delphi2009和Delphi2010中用法

Delphi 取出一个字符在字符串出现的次数

Delphi processid, process handle, window handle 之间的互相转换

Delphi图片增加文字水印

Delphi和金山词霸制作批量单词翻译

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...