?
Solved

Event handler for control notifications?

Posted on 1998-09-15
4
Medium Priority
?
326 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 200 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

840 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