67194:67194 > 玩儿转嵌入式开发
[导读]//?MouseHook.h? #ifdef?MOUSEHOOK_EXPORTS #define?MOUSEHOOK_API?__declspec(dllexport) #else #define?

//?MouseHook.h?

#ifdef?MOUSEHOOK_EXPORTS
#define?MOUSEHOOK_API?__declspec(dllexport)
#else
#define?MOUSEHOOK_API?__declspec(dllimport)
#endif

extern?"C"?MOUSEHOOK_API?void?CALLBACK?InstallMouseHook(void);
extern?"C"?MOUSEHOOK_API?void?CALLBACK?UnMouseHook(void);

extern?"C"?MOUSEHOOK_API?LRESULT?CALLBACK?MouseHookProc(int?nCode,?WPARAM?wParam,?LPARAM?lParam);

//?MouseHook.cpp?
//?MouseHook.cpp?:?Defines?the?entry?point?for?the?DLL?application.
//

#include?"stdafx.h"
#include?"MouseHook.h"
#include//?告诉编译器将变量放入它自己的数据共享节中
#pragma?data_seg("MouseHookData")

HINSTANCE?ghInst?=?NULL;
HHOOK?ghMouseHook?=?NULL;

#pragma?data_seg()

//?告诉编译器设置共享节的访问方式为:读,写,共享
#pragma?comment(linker,?"/SECTION:MouseHookData,RWS")

BOOL?APIENTRY?DllMain(HANDLE?hModule,DWORD??ul_reason_for_call,LPVOID?lpReserved)
{
??switch(ul_reason_for_call)
??{
??case?DLL_PROCESS_ATTACH:
????ghInst?=?(HINSTANCE)hModule;
????break;
??case?DLL_THREAD_ATTACH:
??case?DLL_THREAD_DETACH:
??case?DLL_PROCESS_DETACH:
????break;
??}
????return?TRUE;
}

extern?"C"?MOUSEHOOK_API?void?InstallMouseHook(void)
{
??RETAILMSG(1,(L"[Mouse?HOOK]Install?HOOK:?0x%xrn",ghInst));
??if(ghInst)
??{
????ghMouseHook?=?SetWindowsHookEx(WH_MOUSE_LL,?MouseHookProc,?ghInst,?0);
????if(NULL?==?ghMouseHook)
????{
??????RETAILMSG(1,(L"[Mouse?HOOK]HOOK?create?failed:?%drn",GetLastError()));
????}
??}
}

extern?"C"?MOUSEHOOK_API?void?UnMouseHook(void)
{
??RETAILMSG(1,(L"[Mouse?HOOK]Uninstall?HOOK:0x%xrn",ghMouseHook));
??if(ghMouseHook)
??{
????UnhookWindowsHookEx(ghMouseHook);
????ghMouseHook?=?NULL;
??}

??ghInst?=?NULL;
}

/*
nCode
[输入参数]?说明?HOOK?过程如何处理此消息。如果?nCode?小于零,?HOOK?过程必须将此消息直接传递给下一个?CallNextHookEx,?并从?CallNextHookEx?返回.
??本参数可以取以下的值:HC_ACTION
wParam?和?lParam?参数中包含鼠标消息的信息。
wParam
[输入参数]?鼠标消息标识.?本参数取如下值之一:?WM_LBUTTONDOWN,?WM_LBUTTONUP,?WM_MOUSEMOVE,?WM_MOUSEWHEEL,?WM_MOUSEHWHEEL,?WM_RBUTTONDOWN,?或?WM_RBUTTONUP.?
lParam
[输入参数]?指定?MSLLHOOKSTRUCT?结构体.?其中包含坐标等信息。
*/
//?CE6?的鼠标?HOOK?的响应速度很慢,?原因不明!
extern?"C"?MOUSEHOOK_API?LRESULT?MouseHookProc(int?nCode,?WPARAM?wParam,?LPARAM?lParam)
{
??static?POINT?ptPre;

#if?_DEBUG
???RETAILMSG(1,(L"[Mouse?HOOK]Mouse?Proc,nCode?is:?%drn",nCode));
???RETAILMSG(1,(L"[Mouse?HOOK]Mouse?Proc,wParam?is:?%drn",wParam));
#endif
??PMSLLHOOKSTRUCT?pMouseHookStruct?=?(PMSLLHOOKSTRUCT)lParam;
#if?_DEBUG
??RETAILMSG(1,(L"[Mouse?HOOK]Mouse?Proc,mouseData?is:?%drn",pMouseHookStruct->mouseData));
??RETAILMSG(1,(L"[Mouse?HOOK]Mouse?Proc,dwExtraInfo?is:?%drn",pMouseHookStruct->dwExtraInfo));
#endif

??if(HC_ACTION?!=?nCode)
??{
????return?CallNextHookEx(ghMouseHook,?nCode,?wParam,?lParam);
??}

??if(ptPre.x?!=?pMouseHookStruct->pt.x?||?ptPre.y?!=?pMouseHookStruct->pt.y)
??{
#if?_DEBUG
????RETAILMSG(1,(L"[Mouse?HOOK]Mouse?Proc,pt?is:?%d,%d(%d,%d)rn",pMouseHookStruct->pt.x,pMouseHookStruct->pt.y,ptPre.x,ptPre.y));
#endif
????ptPre?=?pMouseHookStruct->pt;

????//?若注释掉此句,?则不再响应鼠标操作
????return?CallNextHookEx(ghMouseHook,?nCode,?wParam,?lParam);??//?继续传递消息
??}

??return?TRUE;
}

//?调用示例

//?mouse?hook?test
typedef?void?(*pInstallMouseHook)(void);
typedef?void?(*pUnMouseHook)(void);
HINSTANCE?ghMouseModule?=?NULL;
pInstallMouseHook??InMouseHook?=?NULL;
pUnMouseHook??UnMouseHook?=?NULL;


ghMouseModule?=?LoadLibrary(L"\AppStore\SystemInfo\MouseHook.dll");
if(ghMouseModule)
{
??InMouseHook?=?(pInstallMouseHook)GetProcAddress(ghMouseModule,L"InstallMouseHook");
??UnMouseHook?=?(pUnMouseHook)GetProcAddress(ghMouseModule,L"UnMouseHook");
}
if(NULL?!=?InMouseHook)
{
??InMouseHook();
}


玩儿转嵌入式开发

327 篇文章

关注

发布文章

技术子站

更多

论坛活动

  • 新年历,ADI精品视频课堂开始啦
    新年历,ADI精品视频课堂开始啦
  • 【看视频赢好礼】贸泽电子视频课程大讲堂
  • RT-Thread应用创新设计大赛,报名即领开发板~
  • 21ic下载站“资源奖励计划”升级!再发3450元~
更多

资料下载

  • (网盘)刘凯老师STM32视频教程及配套资源
  • (网盘)电路精讲班视频
  • 龙芯2k lite 开发板教育派硬件规格
  • (网盘)电路强化班视频
  • Beken BK7252 麻雀一号开发板
  • 最全Altium designer封装库700MB(含3D模型),网盘分享
  • (网盘)quartus基本语法等
  • (网盘)stm32四轴飞行器资料
  • 雅特力 AT-START-F403A开发板
  • 非接触式电子体温计(额温枪)PCB+程序源码
XML 地图 | Sitemap 地图