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检测android mock位置

Delphi 从记事本导入记录

Delphi gridpanel percent百分比设置

Delphi + word = 数据库 + 公文处理

Delphi中tapplicationevents控件的用途与使用方法

Delphi 调出windows 系统时间设置对话框

Delphi winapi: getparent - 判断两个窗口是不是父子关系

Delphi datetimepicker控件日期格式

Delphi计算两个时间差

Delphi保存网页中的图片

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



打赏

取消

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

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

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

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

评论

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