-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRichEditURL.pas
74 lines (58 loc) · 1.56 KB
/
RichEditURL.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
unit RichEditURL;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Controls,
ComCtrls, ExtCtrls, RichEdit;
type
TURLClickEvent = procedure(Sender :TObject; const URL: string) of object;
TRichEditURL = class(TRichEdit)
private
FOnURLClick: TURLClickEvent;
procedure CNNotify(var Msg: TWMNotify); message CN_NOTIFY;
protected
procedure DoURLClick (const URL : string);
procedure CreateWnd; override;
published
property OnURLClick : TURLClickEvent read FOnURLClick write FOnURLClick;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('delphi.about.com', [TRichEditURL]);
end;
{ TRichEditURL }
procedure TRichEditURL.DoURLClick(const URL : string);
begin
if Assigned(FOnURLClick) then OnURLClick(Self, URL);
end; (*DoURLClick*)
procedure TRichEditURL.CNNotify(var Msg: TWMNotify);
var
p: TENLink;
sURL: string;
begin
if (Msg.NMHdr^.code = EN_LINK) then
begin
p := TENLink(Pointer(Msg.NMHdr)^);
if (p.Msg = WM_LBUTTONDOWN) then
begin
try
SendMessage(Handle, EM_EXSETSEL, 0, Longint(@(p.chrg)));
sURL := SelText;
DoURLClick(sURL);
except
end;
end;
end;
inherited;
end; (*CNNotify*)
procedure TRichEditURL.CreateWnd;
var
mask: Word;
begin
inherited CreateWnd;
SendMessage(Handle, EM_AUTOURLDETECT,1, 0);
mask := SendMessage(Handle, EM_GETEVENTMASK, 0, 0);
SendMessage(Handle, EM_SETEVENTMASK, 0, mask or ENM_LINK);
end; (*CreateWnd*)
end. (* RichEditURL.pas *)