unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Forms, StdCtrls, ComCtrls;
type
TForm1 =
class(TForm)
RichEdit1: TRichEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure WmNotify(
var Message: TWMNotify);
message WM_NOTIFY;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
RichEdit, ShellAPI;
procedure TForm1.WmNotify(
var Message: TWMNotify);
type
PENLink = ^TENLink;
TTextRange = TTextRangeA;
var
Link:
string;
Text: TTextRange;
begin
inherited;
with Message do
if (Result = Ord(False))
and Assigned(NMHdr)
and (NMHdr.code = EN_LINK)
then
with PENLink(NMHdr)^
do
if msg = WM_LBUTTONDOWN
then
begin
SetLength(Link, chrg.cpMax - chrg.cpMin + 1);
Link[1] := #0;
Text.chrg := chrg;
Text.lpstrText := PChar(Link);
SendMessage(NMHdr.hwndFrom, EM_GETTEXTRANGE, 0, Integer(Addr(Text)));
if StrLen(PChar(Link)) > 0
then
begin
ShellExecute(
Handle, '
open', PChar(Link),
nil,
nil, SW_SHOWDEFAULT);
Result := Ord(True);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with RichEdit1
do
begin
Perform(EM_AUTOURLDETECT, Ord(True), 0);
Perform(EM_SETEVENTMASK, 0, Perform(EM_GETEVENTMASK, 0, 0)
or ENM_LINK);
end;
end;
end.