屏蔽控件的右键菜单
方法1:拦截系统消息
在form上添加一个Application Events控件,然后在其OnMessage事件中输入一下代码:
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
if Msg.message = WM_RBUTTONDOWN then
begin
//如果去掉下面这行就是屏蔽右键菜单,现在为自定义右键菜单
popupmenu1.Popup(Mouse.CursorPos.X, Mouse.CursorPos.Y);
Handled := True;
end;
end;
方法2:拦截控件的右键消息,代码如下:
type
TMyReal = class(TRealAudio)
public
procedure TWMRBUTTONDOWN(var msg:TMsg);
message WM_RBUTTONDOWN;
end;
procedure TMyReal.TWMRBUTTONDOWN(var msg:TMsg);
var
P:Tpoint;
begin
if popupmenu<>nil then
//加入自己的事件
begin
GetCursorPos(p);
//获得当前鼠标位置
popupmenu.Popup(p.x,p.y);
//弹出菜单
end;
end;
好象也不好使