Link to home
Start Free TrialLog in
Avatar of skanade
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
Avatar of Madshi
Madshi

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.NMHdr))^ do
          if Msg = wm_SetCursor then
          begin
            SetCursor(Screen.Cursors[crHandPoint]);
            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.Handle, 'open', TextRange.URL, nil, nil, sw_ShowNormal);
              Message.Result := 1;
            finally
              StrDispose(TextRange.URL);
            end;
      EN_OLEOPFAILED: ;
    end;
end;

Avatar of skanade

ASKER

Hagen,

Thanks! That worked. Please put a comment as answer so that I can give you the points.

Sanjay
ASKER CERTIFIED SOLUTION
Avatar of Hagen040798
Hagen040798

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial