馒头学Delphi

Delphi中禁止WebBrowser右键的方法

uses MSHtml;

//在控件标签additional中找到TApplicationEvents控件,拖到窗体上.在TApplicationEvents的OnMessage事件中加入以下代码:
//替换右键菜单

procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
var
mPoint: TPoint;
begin
if IsChild(WebBrowser.Handle, Msg.Hwnd) and
((Msg.Message
= WM_RBUTTONDOWN) or (Msg.Message = WM_RBUTTONUP)) then
begin
GetCursorPos(mPoint);
//得到光标位置
pm5.Popup(mPoint.X, mPoint.Y);
//弹出popupmenu1的菜单
Handled :
= True;
end;
end;

或者
//屏蔽右键菜单

procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
begin
with Msg do
begin
if not IsChild(WebBrowser1.Handle, hWnd) Exit;
Handled :
= (message = WM_RBUTTONDOWN) or (message = WM_RBUTTONUP) or (message = WM_CONTEXTMENU);
end;
end;

 

posted on 2010-06-26 11:20  swlove  阅读(1579)  评论(0编辑  收藏  举报

导航