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 把一个ico转换为bmp

Delphi 用浏览器来显示带图片的邮件内容,图片无需保存为本地文件

Delphi 查找并删除过期的日志目录

Delphi waitforsingleobject 响应窗体

Delphi 删除字符串中指定字符

Delphi 在目录后面加上一个 "\"

Delphi判断mssql数据库中表格是否存在? 如何批量创建表格?

Delphi 控制台程序获取系统信息

Delphi edit 让密码变成点

Delphi 操作“任务栏”

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



打赏

取消

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

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

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

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

评论

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