windowsHOOK消息真心不知道HOOK了些什么和什么

#define _WIN32_WINNT 0x500
#include <windows.h>




static LRESULT CALLBACK hookproc(UINT nCode,WPARAM wParam,LPARAM lParam);
BOOL _stdcall InstallMyHook(HWND hWnd);
BOOL _stdcall UninstallMyHook(HWND hWnd);


HHOOK hook;
HWND hWndMain;
HINSTANCE hInst=GetModuleHandle("MouseDll.dll");


BOOL _stdcall InstallMyHook(HWND hWnd){
hook=SetWindowsHookEx(WH_MOUSE_LL,(HOOKPROC)hookproc,hInst,0);
//SetWindowsHookEx()
if(!hook)
{
DWORD reason=GetLastError();
LPCSTR tt=(LPCSTR)&reason;
//CString str;
// str.Format("%c",reason);
MessageBox(hWnd,tt,"HHOOK",MB_OK);
// OutputDebugString(reason);
return FALSE;
}
hWndMain=hWnd;
return TRUE;
} // HOOK安装


BOOL _stdcall UninstallMyHook(HWND hWnd)
{
if(hWnd != hWndMain || hWnd==NULL)
return FALSE;
BOOL unhooked=UnhookWindowsHookEx(hook);
if(unhooked)
hWndMain=NULL;
return unhooked;
}


static LRESULT CALLBACK hookproc(UINT nCode,WPARAM wParam,LPARAM lParam)
{
if(wParam == WM_MOUSEMOVE)
{
MOUSEHOOKSTRUCT *mhookstruct;
mhookstruct=(MOUSEHOOKSTRUCT*)lParam;
POINT pt=mhookstruct->pt;
PostMessage(hWndMain,WM_MOUSEMOVE,MK_CONTROL,MAKELPARAM(pt.x,pt.y));
}
return CallNextHookEx(hook,nCode,wParam,lParam);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值