帖个HOOK鼠标滚轮滚动的DLL。(我很菜,大家板砖少点,谢谢合作!!)
//==================================== library hookprj; uses SysUtils, Classes, Unit1 in 'Unit1.pas'; exports EnableMsgHook, //只要把这两个函数输出就可以了, DisableMsgHook;// begin end. //====================================
//==================================== unit Unit1;
interface
uses Windows,Messages;
var HookHandle: HHOOK;//钩子的句柄值。
function MsgHookProc(Code: Integer; WParam: Longint;Msg:Longint): LRESULT;stdcall; //鼠标钩子的回调函数,即是用它来处理得到消息后要干什么。。 //nCode参数是Hook的标志,一般只关心小于0时。 //WParam参数表示鼠标消息的类型 //LParam参数是一个指向 TMOUSEHOOKSTRUCT 结构的指针。结构包含了鼠标消息的状态,我只用了hwnd一个 //即鼠标消息要传递给的窗口句柄。 //返回值如果不是0的话windows就把这个消息丢掉,其它的程序就不会再收到这个消息了。
function EnableMsgHook:Boolean; stdcall; export; function DisableMsgHook:Boolean; stdcall; export;//两个函数都是Boolean类型,成功都是返回True implementation
function MsgHookProc(Code: Integer; WParam: Longint;Msg:Longint): LRESULT;stdcall; begin if (Code = HC_ACTION) then if PMsg(Msg)^.Message = WM_MOUSEWHEEL then //鼠标滚动 begin if HIWORD(PMsg(Msg)^.wParam)=120 then // 上滚 begin //做你想做的。 ShowWindow (pmsg(msg)^.hwnd,SW_MAXIMIZE ); end;
if HIWORD(PMsg(Msg)^.wParam)<>120 then // 下滚 begin //做你想做的。 ShowWindow (pmsg(msg)^.hwnd,SW_RESTORE ); end; PMsg(Msg)^.Message := 0; end; Result :=CallNextHookEx(HookHandle, Code, WParam, Longint(@Msg)); end;
function EnableMsgHook:Boolean; stdcall; export; begin if HookHandle = 0 then //为了安全,必须判断一下再设置钩子。 Begin // 第三个参数的Hinstance 在Delphi中有定义,用就可以了。第四个参数必须为0 HookHandle := SetWindowsHookEx(WH_GETMESSAGE,@MsgHookProc,Hinstance,0); Result := True; end else Result := False; end;
function DisableMsgHook:Boolean; stdcall; export; begin if HookHandle <> 0 then //如果有钩子就卸掉他。 begin UnHookWindowsHookEx(HookHandle); HookHandle := 0; Result := True; end else Result := False; end;
end.
//====================================
接口函数是EnableMsgHook和,DisableMsgHook。怎么用,大家应该清楚吧,本人对DELPHI比较菜,有不好的地方望大家指出,改正!!! 
|