怎样屏蔽掉webbrowser的鼠标右键(150分)(150分)

  • 主题发起人 主题发起人 wolfsong
  • 开始时间 开始时间
W

wolfsong

Unregistered / Unconfirmed
GUEST, unregistred user!
给个hook的好例子,拜托。
 
再加一句:还得把windows热键屏蔽掉:apps键
 
做触摸屏吧
有办法的,我找找
 
go to www.euromind.com/iedelphi 看看 ,里面很多关于IE设置的办法!
 
以前没用hook,吃掉过webbrowser右键,可吃不掉winapps键
给个吃掉apps的法子吧(不用放到hook里),给解决代码的话,另给50分
本题目保证150,保证不食言
 
完美解决方案(你想屏蔽什么键都可以):
下面的代码只对初始化过的WebBrowser的菜单生效,即WebBrowser已经Navigate过某一页
如果对未Navigate的WebBrowser,可以直接弹出其PopupMenu属性里设的菜单。

const
WM_POPUP_DXMENU = WM_USER + 1000;

private
{ Private declarations }
OldWBWndProc: TWndMethod;
procedure WBWndProc(var Message: TMessage);
procedure WmPopupMymenu(var Msg: TMsg); message WM_POPUP_DXMENU;

procedure TForm1.WBWndProc(var Message: TMessage);
begin
with Message do
begin
if ((Msg = WM_PARENTNOTIFY) and (LOWORD(WPARAM) = WM_RBUTTONDOWN)) or
(WPARAM = VK_APPS) then
PostMessage(Handle, WM_POPUP_DXMENU, LOWORD(LPARAM), HiWord(LPARAM));//通知主窗体要弹出菜单
if (GetAsyncKeyState(VK_CONTROL) and (1 shl 16)) <> 0 then //按Ctrl+A全选 Ctrl+C(X)拷贝到剪贴板
case WPARAM of
Ord('A'):
WebBrowser.ExecWB(OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT);
Ord('C'), Ord('X'):
WebBrowser.ExecWB(OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT);
end;
//if WPARAM = VK_ESCAPE then 你还可以象这样拦其他的键
if (Msg < (CN_BASE + WM_KEYFIRST)) or (Msg > (CN_BASE + WM_DEADCHAR)) then
OldWBWndProc(Message);
end;
end;

procedure TForm1.Loaded;
begin
inherited;
if not (csDesigning in ComponentState) then
begin
OldWBWndProc := WebBrowser.WindowProc;
WebBrowser.WindowProc := WBWndProc;
end;
end;

procedure TCQContractView.WmPopupMymenu(var Msg: TMsg);
begin
PopupDxBarMenu; //弹出自己的菜单
end;

我已在现有项目中使用此方法,如有什么问题请提出。
 
小弟写了一个Internet Explorer设置的软件,几乎包含了IE的所有设置,特别是对Internet
选项的设置。
我写这个软件的目的有两个:1.我的一个很好的老师因为上了“不规范”的网站,将IE搞的
无法正常使用;2.我在网吧兼职,老板说有些东西不让用,呵呵,用她轻轻设置一下就搞定。
各位大哥,需要软件的给我写信jollier@371.net
来信必复软件。[:)]
 
to xianjun:
tform好像没有loaded事件(TNND,vb都有);
TCQContractView报错,说没这个玩意
 
procedure TForm1.Loaded;不是事件,而是一个方法,从TComponent下来的。
你在public里这样写:procedure Loaded; override;
TCQContractView应该改成你的窗体类名,我一下子改漏了。
 
屏蔽掉webbrowser的鼠标右键,没做过,但感觉应该不是很难。
获得句柄,再蔽掉RBUTTON_CLICK或者WM_LBUTTONDOWN消息,其实就是对WM_MOUSEACTIVATE的处理。
 
to xianjun:
不行。仍然有,要不给你我以前的你帮我改改,能干掉webbrowser的右键,
干不掉vk_apps, TNND
unit mainfrm;

interface

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

type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure mymessage(var msg:tmsg;var handled:boolean);
end;

var
Form1: TForm1;

implementation

{$R *.dfm}


procedure tform1.mymessage(var msg:tmsg;var handled:boolean);
begin
if ((msg.message=wm_rbuttondown)or (msg.message=WM_RBUTTONDBLCLK)
or(msg.wParam=vk_apps)) then
begin
handled:=true;
end;
end;



procedure TForm1.FormCreate(Sender: TObject);
begin
webbrowser1.Navigate('http://WWW.DELPHIBBS.COM');
Application.OnMessage:=mymessage;
end;

end.
 
我还是照我的思路写了一个,你试试吧,我这里是成功了的。
unit Unit1;

interface

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

const
WM_POPUP_DXMENU = WM_USER + 1000;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
PopupMenu1: TPopupMenu;
asdfasdf1: TMenuItem;
qwerqwer1: TMenuItem;
N123412341: TMenuItem;
qerqwer1: TMenuItem;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
OldWBWndProc: TWndMethod;
procedure WBWndProc(var Message: TMessage);
procedure WmPopupMymenu(var Msg: TMsg); message WM_POPUP_DXMENU;

public
{ Public declarations }
procedure Loaded; override;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
webbrowser1.Navigate('http://WWW.DELPHIBBS.COM');
end;

procedure TForm1.Loaded;
begin
inherited;
if not (csDesigning in ComponentState) then
begin
OldWBWndProc := WebBrowser1.WindowProc;
WebBrowser1.WindowProc := WBWndProc;
end;
end;

procedure TForm1.WBWndProc(var Message: TMessage);
begin
with Message do
begin
if ((Msg = WM_PARENTNOTIFY) and (LOWORD(WPARAM) = WM_RBUTTONDOWN)) or
(WPARAM = VK_APPS) then
PostMessage(Handle, WM_POPUP_DXMENU, LOWORD(LPARAM), HiWord(LPARAM)); //通知主窗体要弹出菜单
if (GetAsyncKeyState(VK_CONTROL) and (1 shl 16)) <> 0 then //按Ctrl+A全选 Ctrl+C(X)拷贝到剪贴板
case WPARAM of
Ord('A'):
WebBrowser1.ExecWB(OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT);
Ord('C'), Ord('X'):
WebBrowser1.ExecWB(OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT);
end;
if WPARAM = VK_ESCAPE then
ShowMessage('BackSpace Pressed!');
if (Msg < (CN_BASE + WM_KEYFIRST)) or (Msg > (CN_BASE + WM_DEADCHAR)) then
OldWBWndProc(Message);
end;
end;

procedure TForm1.WmPopupMymenu(var Msg: TMsg);
var
FPoint: TPoint;
begin
GetCursorPos(FPoint);
if not PtInRect(WebBrowser1.ClientRect, WebBrowser1.ScreenToClient(FPoint)) then
FPoint := WebBrowser1.ClientToScreen(Point(1, 1));
PopupMenu1.Popup(FPoint.X{MAXINT 把这个设为MAXINT就是屏蔽的效果了}, FPoint.Y);
end;

end.

DFM:
object Form1: TForm1
Left = 191
Top = 107
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
OldCreateOrder = False
PopupMenu = PopupMenu1
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 12
object WebBrowser1: TWebBrowser
Left = 8
Top = 8
Width = 653
Height = 429
TabOrder = 0
ControlData = {
4C0000007D430000572C00000000000000000000000000000000000000000000
000000004C000000000000000000000001000000E0D057007335CF11AE690800
2B2E126208000000000000004C0000000114020000000000C000000000000046
8000000000000000000000000000000000000000000000000000000000000000
00000000000000000100000000000000000000000000000000000000}
end
object PopupMenu1: TPopupMenu
Left = 80
Top = 28
object asdfasdf1: TMenuItem
Caption = 'asdfasdf'
end
object qwerqwer1: TMenuItem
Caption = 'qwerqwer'
end
object N123412341: TMenuItem
Caption = '12341234'
end
object qerqwer1: TMenuItem
Caption = 'qerqwer'
end
end
end
 
忘了一点东西:
initialization
OleInitialize(nil);

finalization
OleUninitialize();

 
to xiaojun:
还是不行,如果先点左键再点右键再松左键,还是出来(跟破javascript一样)
估计是没加你后来补充的缘故,加哪?
还有,vk_apps仍然不能干掉

这个帖子我想得到hook例子
关于吃掉vk_apps,我想再开个帖子讨论。你进来吧,给分一定给的
 
用application的onmessage不行吗?

if (Msg.message=wm_rbuttondown)or(Msg.message=wm_rbuttonup))and (鼠标是否在webbrower内)then begin
Handled:=true;
end;

 
详细一点

放一个ApplicationEvents,在OnMessage中.........

procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
var
mPoint : TPoint;
begin
if IsChild(WebBrowser1.Handle, Msg.Hwnd) and
((Msg.Message = WM_RBUTTONDOWN) or (Msg.Message = WM_RBUTTONUP)) then
begin
GetCursorPos(mPoint);
PopupMenu1.Popup(mPoint.X, mPoint.Y);
Handled:=True;
end;
end;
 
to zhihuali:
我想解决的是vk_apps,不是右键,右键我已经干掉
 好了,这个帖子我想得到的是个hook例子,我再开个帖子,非hook的大家在那里讨论吧
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
812
SUNSTONE的Delphi笔记
S
S
回复
0
查看
720
SUNSTONE的Delphi笔记
S
I
回复
0
查看
972
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部