Solved

Event handler for control notifications?

Posted on 1998-09-15
4
316 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:skanade
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1339766
Don't know. But I think handling WM_COMMAND is the only/best way...
0
 
LVL 2

Expert Comment

by:Hagen040798
ID: 1339767
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;

0
 

Author Comment

by:skanade
ID: 1339768
Hagen,

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

Sanjay
0
 
LVL 2

Accepted Solution

by:
Hagen040798 earned 50 total points
ID: 1339769
Hi

my Answer.
When you will more from RichEdit-programming, i can you help.
When you not will make a Descend vom TRichEdit, you can the TRichEdit dynamicly subclassing (D3).

type
  TForm1 = class(TForm)
    RichEdit1: TRichEdit;
    procedure FormCreate(Sender: TObject);
  private
    SaveWndProc: TWndMethod;
    procedure RichEditWndProc(var Msg: TMessage);
  end;

procedure TForm1.FormCreate(Sender: TObject)
begin
  SaveWndProc := RichEdit1.WndProc;
  RichEdit1.WndProc := RichEditWndProc;
end;

procedure TForm1.RichEditWndProc(var Msg: TMessage);
begin
  if Msg.Msg = cn_Notify then
    with TWMNotify(Msg).NMHdr^ do    
      case Code of
        en_Link:
          begin
            Exit;
          end;
      end;
  SaveWndProc(Msg);
end;

Thanks for the points. Hagen.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question