安全的鼠标全局钩子---代码粘贴

一个鼠标全局钩子做了3天,3天里充分理解了温故而知新的道理,呵呵。大道理少讲现在我们来 看代码:

1、Hook Dll Code:

Mouse

unit MouseHook;

interface
uses
  Windows,Messages,MousehookConst,Forms,SysUtils;

var
  NextHook:HHOOK;
  MessageHook:HHook;
  ShareData:PShareMem;
  HMapFilehandle: THandle;


function InstallMouseHook(Sender:HWND;MessageID:DWORD;x,y,width,height:integer):Boolean ;stdcall;
function UnInstallMouseHook:Boolean ;stdcall;
Function PauseMouseHook:boolean;stdcall;
Function StartMouseHook:Boolean;stdcall;
function CreateShareMemory:Boolean;stdcall;
Procedure  DestroySharememory;stdcall;
Procedure EntryPointProc(dwReason:DWORD);


implementation


 Procedure EntryPointProc(dwReason:DWORD);
 begin
    case dwReason of
    DLL_PROCESS_ATTACH:CreateShareMemory;
    DLL_PROCESS_DETACH:DestroySharememory;
  end;
 end;

function MouseHookCallBack(Code: integer; Msg: WPARAM;
  MouseHook: LPARAM): LRESULT; stdcall; export;
begin
    Result  := 0;
    if Code<0 then
        Result := CallNextHookEx(NextHook,Code,Msg,MouseHook);
    if ShareData^.PauseFlage then exit;
    case Msg of
      WM_LBUTTONDOWN:
         begin

         end;
      WM_LBUTTONUP :
         begin

         end;
      WM_LBUTTONDBLCLK:
         begin

         end;
      WM_RBUTTONDOWN:
         begin

         end;
      WM_MOUSEMOVE,WM_NCMOUSEMOVE:
         begin
            //if  PMouseHookStruct(MouseHook)^.pt.X>800 then
                //SetCursorPos(800,PMouseHookStruct(MouseHook)^.pt.y);
           if ShareData=nil then
           begin
             Result := CallNextHookEx(NextHook,Code,Msg,MouseHook);
             exit;
           end;
            ShareData^.Data2 := PMouseHookStruct(MouseHook)^;
            SendMessage(ShareData^.Hwnd,Sharedata^.MessageID,Msg,Integer(@ShareData^.Data2));
         end;

      WM_NCMOUSEHOVER:
     

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值