Solved

Event handler for control notifications?

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

696 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