unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ShellApi,RichEdit, StdCtrls, ComCtrls;
type
TForm2 = class(TForm)
RichEdit1: TRichEdit;
RichEdit2: TRichEdit;
procedure FormCreate(Sender: TObject);
private
procedure InitRichEditURLDetection(RE : TRichEdit);
{ Private declarations }
public
protected
procedure WndProc(var Msg: TMessage); override;
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.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 TForm2.FormCreate(Sender: TObject);
var
s: string;
begin
InitRichEditURLDetection(RichEdit1);
s:='Great Delphi tutorials and articles at ' +
'http://www.delphi.about.com.' + #13#10 +
'About Delphi Programming site!' + #13#10 +
'Send an email to your Guide: mailto:delphi.guide@about.com';
RichEdit1.Text := s;
s:= 'http://www.delphi.about.com. ' +
' This Rich Edit does not recognize URLs!';
RichEdit2.Text := s
end;
procedure TForm2.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(Form2.ActiveControl);
SendMessage(CE.Handle, EM_EXSETSEL, 0, Longint(@(p.chrg)));
sURL := CE.SelText;
ShellExecute(Handle, 'open', PChar(sURL), 0, 0, SW_SHOWNORMAL);
except
end;
end;
end;
end;
inherited;
end; (* TForm2.WndProc *)
end.