Delphi 使Richedit中的链接可以点击
2023-01-03 14:33:16 作者:admin
本文整理自网络,侵删。
unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, RichEdit, ShellAPI;
type TForm1 = class(TForm) RichEdit1: TRichEdit; procedure FormCreate(Sender: TObject); private { Private declarations } public procedure WndProc(var Msg: TMessage); override; end;
var Form1: TForm1;
implementation
{$R *.dfm}
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);end;
procedure TForm1.WndProc(var Msg: TMessage);var p: TENLink; sURL: string; CE : TRichEdit;begin if (Msg.Msg = WM_NOTIFY) then begin if (PNMHDR(Msg.lParam).code = EN_LINK) then begin p := TENLink(Pointer(TWMNotify(Msg).NMHdr)^); if (p.Msg = WM_LBUTTONDOWN) then begin try CE := tRichEdit(Self.ActiveControl); SendMessage(CE.Handle, EM_EXSETSEL, 0, Longint(@(p.chrg))); sURL := CE.SelText; ShellExecute(0, 'open', PChar(sURL), 0, 0, SW_SHOWNORMAL); except end; end; end; end; inherited;end;
end.
相关阅读 >>
Delphi firedac 获取mysql 数据库databases 列表
Delphi 全局的鼠标钩子 使用钩子函数数据传递
Delphi xe 与plc通讯(intcpserver 二进制)
Delphi 使用tmemorystream保存多张图片到文件,并读取
Delphi产生不重复随机数的算法
Delphi 10.2 ide界面
Delphi 正则表达式tperlregex 详解
Delphi中禁止webbrowser右键的方法
Delphi 获取文件crc和md5
Delphi 从网址链接中提取域名
更多相关阅读请进入《Delphi》频道 >>
猜你喜欢
联络方式:
400-123-789
邮箱:xiachao@163.com
Q Q:12345678
微信公众号
微信二维码