我还是照我的思路写了一个,你试试吧,我这里是成功了的。
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