16,472
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#define DECLDIR extern "C" __declspec(dllexport)
HINSTANCE g_hInst;
HHOOK g_hMouseHook;
DECLDIR BOOL SetHook();
DECLDIR BOOL ReleaseHook();
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam);
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
g_hInst = (HINSTANCE)hModule;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
BOOL SetHook()
{
g_hMouseHook = SetWindowsHookEx(WH_MOUSE, MouseProc, g_hInst, 0);
return (g_hMouseHook != NULL);
}
BOOL ReleaseHook()
{
return UnhookWindowsHookEx(g_hMouseHook);
}
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
return CallNextHookEx(g_hMouseHook, nCode, wParam, lParam);
}
g_hMouseHook = SetWindowsHookEx(WH_MOUSE, MouseProc, g_hInst, 0);
之后再发送一个