?
Solved

How can I control message for TMemo component

Posted on 2010-01-11
4
Medium Priority
?
355 Views
Last Modified: 2013-11-23
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
Comment
Question by:gamjaradio
[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 38

Expert Comment

by:Geert Gruwez
ID: 26282487
don't you mean right-click ?
0
 

Author Comment

by:gamjaradio
ID: 26282505
Yes Right click - -
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 26282514
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
 
LVL 23

Accepted Solution

by:
Ferruccio Accalai earned 2000 total points
ID: 26283089
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

Industry Leaders: 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

764 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