unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; procedure FormCreate(Sender: TObject); private procedure MyProcedure(var Msg: TMsg; var Handled: Boolean); { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.MyProcedure(var Msg: TMsg; var Handled: Boolean); begin if msg.message=WM_RBUTTONDOWN then msg.message:=WM_NULL; end; procedure TForm1.FormCreate(Sender: TObject); begin application.OnMessage:=MyProcedure; end; end.
如果你只想屏蔽edit1的右键菜单可以将myprocedure改为: procedure TForm1.MyProcedure(var Msg: TMsg; var Handled: Boolean); begin if msg.message=WM_RBUTTONDOWN then if msg.hwnd=edit1.Handle then msg.message:=WM_NULL; end;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
procedure MyProcedure(var Msg: TMsg; var Handled: Boolean);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.MyProcedure(var Msg: TMsg; var Handled: Boolean);
begin
if msg.message=WM_RBUTTONDOWN then
msg.message:=WM_NULL;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
application.OnMessage:=MyProcedure;
end;
end.
procedure TForm1.MyProcedure(var Msg: TMsg; var Handled: Boolean);
begin
if msg.message=WM_RBUTTONDOWN then
if msg.hwnd=edit1.Handle then
msg.message:=WM_NULL;
end;
edit2(如果有的话)或其它控件的右键菜单仍然存在!
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus;type
TForm1 = class(TForm)
Edit1: TEdit;
private
procedure WMContextMenu(var Message: TWMContextMenu); message WM_CONTEXTMENU;
end;var
Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.WMContextMenu(var Message: TWMContextMenu);
begin
if Message.hWnd = Edit1.Handle then
Message.Result := 1;
end;