我做过类似的东西,主要也是在大富翁找了一些资料,基本能屏蔽各种操作,只让用户能浏览word文档。
一个是屏蔽掉鼠标,另一个是注册掉快捷键
1、屏蔽鼠标单元(不知道哪位大侠的,拷贝过来也没理解能用)
unit hook;
interface
uses
forms, extctrls, Windows, Messages, stdctrls, Sysutils, Classes;
var
hkMouse: HHOOK;
hkKey: HHOOK;
f_wnd: Hwnd;
f_rect: TRect;
f_form: TForm;
f_panel: TPanel;
function MouseHookProc(nCode: Integer;WParam: WPARAM;LParam: LPARAM): LRESULT; stdcall;
function EnableMouseHook(a_form: TForm; a_panel: Tpanel; a_wnd: Hwnd):Boolean; stdcall; export;
function DisableMouseHook:Boolean; stdcall; export;
implementation
function MouseHookProc(nCode: Integer;WParam: WPARAM;LParam: LPARAM): LRESULT;stdcall;
var
m: PMOUSEHOOKSTRUCT;
v_rect: TRect;
PEvt: ^EVENTMSG;
begin
Result := 0;
if nCode < 0 then
begin
Result := CallNextHookEx(hkMouse,nCode,WParam,LParam);
exit;
end;
case wParam of
WM_RBUTTONDOWN,
WM_RBUTTONUP,
WM_LBUTTONDOWN,
WM_LBUTTONUP:
begin
m := PMOUSEHOOKSTRUCT(lParam);
v_rect := f_panel.BoundsRect;
MapWindowPoints(f_form.handle, 0, v_rect, 2); // 座标换算
Dec(v_rect.Right, 18);
Dec(v_rect.Bottom, 18);
// 如果鼠标在v_rect范围内
if PtInRect(v_rect, Point(m.pt.x, m.pt.y)) then
// 如果Form处于激活状态
if GetActiveWindow=f_form.handle then
begin
Result := 1; //丢弃消息
exit;
end;
end;
end;
Result := CallNextHookEx(hkMouse, nCode, wParam, lParam);
end;
function EnableMouseHook(a_form: TForm; a_panel: Tpanel; a_wnd: Hwnd):Boolean; stdcall; export;
begin
f_form := a_form;
f_panel := a_panel;
f_wnd := a_wnd;
if hkMouse = 0 then
begin
hkMouse := SetWindowsHookEx(14, @MouseHookProc,Hinstance,0); //使用低级鼠标钩子
Result := True;
end
else
Result := False;
end;
function DisableMouseHook:Boolean; stdcall; export;
begin
if hkMouse <> 0 then
begin
UnHookWindowsHookEx(hkMouse);
hkMouse := 0;
Result := True;
end
else
Result := False;
end;
二、主单元(包括注册快捷键)
窗体中有一pannel,然后webboowser放在上面
unit look;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, LEADVCL,LtVclDef, ltVcltyp,LTLCKVCL,
OleCtrls, SHDocVw, OleCtnrs, Buttons;
type
TlookForm = class(TForm)
Panel1: TPanel;
WebBrowser1: TWebBrowser;
Panel2: TPanel;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
private
procedure HotKeyDown(var Msg: Tmessage); message WM_HOTKEY;
public
{ Public declarations }
end;
type
TWBPosition = (wbPosBottom, wbPosTop, wbPosRight);
var
lookForm: TlookForm;
v_wnd: HWND;
v_rec: TRect;
temp:integer;
HotKeyId,HotKeyId1,HotKeyId2: Integer;
implementation
uses hook;
{$R *.dfm}
procedure TlookForm.HotKeyDown(var Msg: Tmessage);
begin
if (Msg.LparamLo = MOD_CONTROL) AND (Msg.LParamHi =ord('A')) then //
begin
showmessage('查看word文档');
end;
if (Msg.LparamLo = MOD_CONTROL) AND (Msg.LParamHi =ord('C')) then //
begin
showmessage('查看word文档');
end;
if (Msg.LparamLo = MOD_CONTROL) AND (Msg.LParamHi =ord('X')) then //
begin
showmessage('查看word文档');
end;
end;
procedure TlookForm.FormCreate(Sender: TObject);
begin
HotKeyId := GlobalAddAtom('MyHotKey');
HotKeyId1 := GlobalAddAtom('MyHotKey1');
HotKeyId2 := GlobalAddAtom('MyHotKey2');
RegisterHotKey(Handle, hotkeyid, MOD_CONTROL, ord ('A'));
RegisterHotKey(Handle, hotkeyid1, MOD_CONTROL, ord ('C'));
RegisterHotKey(Handle, hotkeyid2, MOD_CONTROL, ord ('X'));
v_wnd := GetActiveWindow;
end;
procedure TlookForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
DisableMouseHook;
UnRegisterHotKey(handle, HotKeyId);
UnRegisterHotKey(handle, HotKeyId1);
UnRegisterHotKey(handle, HotKeyId2);
end;
procedure TlookForm.FormShow(Sender: TObject);
begin
// EnableKeyHook(v_wnd);
EnableMouseHook(lookForm, Panel1, v_wnd);
end;
end.
你可以参考一下。