Solved

Event handler for control notifications?

Posted on 1998-09-15
4
305 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
  • 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now