function MOUSE_Hook(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LResult;
begin
if nCode > -1 then begin
if (wParam = WM_LBUTTONDOWN){or(wParam = WM_LBUTTONUP)} then begin
if Form1.CheckBox1.Checked then begin
Result := -1;
end
else
Result := 0;
end
else if (wParam = WM_RBUTTONDOWN) then begin
Form1.CheckBox1.Checked := False;
Result := 0;
end
else Result := 0;
end
else Result := CallNextHookEx(MOUSEHook, nCode, wParam, lParam);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MOUSEHook := SetWindowsHookEx(WH_MOUSE, @MOUSE_Hook, 0, GetCurrentThreadID);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnHookWindowsHookEx(MOUSEHook);
end;
예제로 마우스HOOK입니다.
체크박스를 체크하면 마우스는 먹통이되구요 마우스우측한번 클릭시
원상복구됩니다.
.
.
.
var
Form1: TForm1;
MOUSEHook: HHOOK;
function MOUSE_Hook(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LResult; stdcall;
implementation
{$R *.dfm}
function MOUSE_Hook(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LResult;
begin
if nCode > -1 then begin
if (wParam = WM_LBUTTONDOWN){or(wParam = WM_LBUTTONUP)} then begin
if Form1.CheckBox1.Checked then begin
Result := -1;
end
else
Result := 0;
end
else if (wParam = WM_RBUTTONDOWN) then begin
Form1.CheckBox1.Checked := False;
Result := 0;
end
else Result := 0;
end
else Result := CallNextHookEx(MOUSEHook, nCode, wParam, lParam);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MOUSEHook := SetWindowsHookEx(WH_MOUSE, @MOUSE_Hook, 0, GetCurrentThreadID);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnHookWindowsHookEx(MOUSEHook);
end;