如何屏蔽TWebBrowser的右键菜单

zy61 2003-07-02 01:29:51
如题
...全文
166 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zy61 2003-07-04
  • 打赏
  • 举报
回复
up
linzhisong 2003-07-02
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, AppEvnts, Menus, StdCtrls;

type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
ApplicationEvents1: TApplicationEvents;
PopupMenu1: TPopupMenu;
N2341: TMenuItem;
N42341: TMenuItem;
Label1: TLabel;
Button1: TButton;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
webbrowser1.Navigate('http:\\localhost');
end;

procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
if ((Msg.message=wm_rbuttondown)or(Msg.message=wm_rbuttonup)) then//and (鼠标是否在webbrower内)then begin
Handled:=true;

end;
zy61 2003-07-02
  • 打赏
  • 举报
回复
ronaldli(木的)的办法好,但是我是否可以区分出是什么样的菜单,我想队bady上的菜单和表单上的菜单有选择的进行屏蔽。
naughtyboy 2003-07-02
  • 打赏
  • 举报
回复
public
{ Public declarations }
procedure OnAppMsg(var msg: tmsg;var handled: boolean);

procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.163.com');
Application.OnMessage := OnAppMsg;
end;

procedure TForm1.OnAppMsg(var msg: tmsg; var handled: boolean);
begin
if (msg.message = wm_rbuttondown) then
begin
showmessage(inttostr(WebBrowser1.Handle));
//showmessage(inttostr(windowfrompoint(ScreenToClient(msg.pt))));
// showmessage(inttostr(msg.lParam));
//showmessage(inttostr(longint(@msg.wParam)));
showmessage('trap browser mouse');
end
else
inherited;
end;

可惜不知道为什么windowfrompoint得到的窗口句柄是form1的句柄,而不是webbrowser的句柄
jun_01 2003-07-02
  • 打赏
  • 举报
回复
哈哈,这样,

在TWebBrowser上放一个TLabel.Caption:=''; Transparent:=true,

就可以自己处理右键了。

naughtyboy 2003-07-02
  • 打赏
  • 举报
回复


procedure OnAppMsg(var msg: tmsg;var handled: boolean);


procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.163.com');
Application.OnMessage := OnAppMsg;
end;

procedure TForm1.OnAppMsg(var msg: tmsg; var handled: boolean);
begin
if (msg.message = wm_rbuttondown) then
begin
showmessage(inttostr(WebBrowser1.Handle));
showmessage(inttostr(windowfrompoint(msg.pt)));
showmessage(inttostr(msg.lParam));
showmessage(inttostr(longint(@msg.wParam)));
showmessage('trap browser mouse');
end
else
inherited;
end;

不过不知道为什么windowfrompoint的得到的不是WebBrowser1的handle,郁闷~~
ronaldli 2003-07-02
  • 打赏
  • 举报
回复
楼上的办法不行,只要我按下右键不放,用回车点去对话框,再抬起右键,菜单还会出来
应该这样写:
<script language="JavaScript">
document.oncontextmenu = function(){ return false }
</script>

但是这种方法也只是让网页不弹出菜单,没有真正让TWebBrowser不弹出菜单
zy61 2003-07-02
  • 打赏
  • 举报
回复
up
esu 2003-07-02
  • 打赏
  • 举报
回复
没有用过WebBrowser
但是可以试试以下:
<!--将以下代码加入HTML的<HEAD></HEAD>之间-->
<script language="javascript">
function click() {
if (event.button==2) {
alert('你想干什么?')
}
}
document.onmousedown=click
</script>
koma2003 2003-07-02
  • 打赏
  • 举报
回复
帮你UP
试过了不行

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧