skanade
asked on
Event handler for control notifications?
I know how to set up my own event handler for a WM_.. message. But, I don't know how to set up one for a control notification message such as EN_PROTECTED or EN_LINK (richedit). Such notifications come through WM_COMMAND. So, I can always set up a WM_COMMAND handler to catch the above. But, I was just wondering whether there is an easier way to do this.
Thanks,
Sanjay
Thanks,
Sanjay
Don't know. But I think handling WM_COMMAND is the only/best way...
for RichEdit you must use this.
type
TMyRichEdit = class(TRichEdit)
protected
procedure CNNotify(var Message: TWMnotify); message cn_Notify;
end;
procedure TMyRichEdit.CNNotify(var Message: TWMNotify);
type
PENLink = ^TENLink;
var
TextRange: packed record
chrg: TCharRange;
URL: PChar;
end;
begin
with Message.NMHdr^ do
case Code of
EN_LINK:
with PENLink(Pointer(Message.NM Hdr))^ do
if Msg = wm_SetCursor then
begin
SetCursor(Screen.Cursors[c rHandPoint ]);
Message.Result := 1;
end else
if Msg = wm_LButtonDblClk then
try
TextRange.URL := StrAlloc(chrg.cpMax - chrg.cpMin + 10);
TextRange.chrg := chrg;
Perform(em_GetTextRange, 0, LongInt(@TextRange));
ShellExecute(Application.H andle, 'open', TextRange.URL, nil, nil, sw_ShowNormal);
Message.Result := 1;
finally
StrDispose(TextRange.URL);
end;
EN_OLEOPFAILED: ;
end;
end;
type
TMyRichEdit = class(TRichEdit)
protected
procedure CNNotify(var Message: TWMnotify); message cn_Notify;
end;
procedure TMyRichEdit.CNNotify(var Message: TWMNotify);
type
PENLink = ^TENLink;
var
TextRange: packed record
chrg: TCharRange;
URL: PChar;
end;
begin
with Message.NMHdr^ do
case Code of
EN_LINK:
with PENLink(Pointer(Message.NM
if Msg = wm_SetCursor then
begin
SetCursor(Screen.Cursors[c
Message.Result := 1;
end else
if Msg = wm_LButtonDblClk then
try
TextRange.URL := StrAlloc(chrg.cpMax - chrg.cpMin + 10);
TextRange.chrg := chrg;
Perform(em_GetTextRange, 0, LongInt(@TextRange));
ShellExecute(Application.H
Message.Result := 1;
finally
StrDispose(TextRange.URL);
end;
EN_OLEOPFAILED: ;
end;
end;
ASKER
Hagen,
Thanks! That worked. Please put a comment as answer so that I can give you the points.
Sanjay
Thanks! That worked. Please put a comment as answer so that I can give you the points.
Sanjay
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.