• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

How can I control message for TMemo component

I set up TMemo in the Form.

And what I wanna do is doing left-click of mouse in TMemo component.
and blocking pop-up menu by checking out WM_CONTEXMENU message.

HOW can I do? Please tell me..
0
gamjaradio
Asked:
gamjaradio
  • 2
1 Solution
 
Geert GruwezOracle dbaCommented:
don't you mean right-click ?
0
 
gamjaradioAuthor Commented:
Yes Right click - -
0
 
Geert GruwezOracle dbaCommented:
you can remove a windows message using
PeekMessage(Msg,  0, WM_MOUSEFIRST, WM_MOUSELAST,  PM_REMOVE);

see this for removing all mouse messages or keyboard messages
http://www.swissdelphicenter.ch/torry/showcode.php?id=1066
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
My little knowledge here.

The TEdit and TMemo (and other edit controls) system popup menu is built directly into the Microsoft edit control and it's not handled by the VCL, so you can't access its handle on the fly.
What we can do is to catch the control message and handle its result by ourself.

Another interesting thing in Delphi is that we can override a TControl creating a descendent class of itself, just to add a procedure that we'll can use for our purpose

In this case I'll go to override the TMemo to add a WMContextMenu to it just to catch the WMContextMenu message and stop it.

So Let's go

Simply put a TMemo on a Form and then past this code
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TMemo = class(StdCtrls.TMemo)//just our original TMemo
  private
    procedure WMContextMenu(var Message: TWMContextMenu); message WM_CONTEXTMENU; //but with a new procedure
  end;

  TForm1 = class(TForm)
    Memo1: TMemo;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

procedure TMemo.WMContextMenu(var Message: TWMContextMenu);
begin
  message.Result := -1; //yes, we tell him to simply do nothing ;-)
end;
{$R *.dfm}

end.

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now