xianjun (2001-11-17 8:40:00)
完美解决方案(你想屏蔽什么键都可以):
下面的代码只对初始化过的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;