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();
}


换一批

延伸阅读

[Linuxer的小圈子] ALSA学习笔记

1 整体架构 ? Application ?--------------- ? Alsa-lib?????????????????? User Space ------------------------------------- ??...

关键字: callback playback

[工程师杂谈] CE 6 下键盘钩子(HOOK)

// 已经写过一个 CE5.0 下的键盘钩子:http://blog.csdn.net/91program/article/details/1961570 // 前一段时间在坛子看到有人在问 CE6.0 下钩子的实现,有的说不行,有的说行,...

关键字: keyboard hook

[玩儿转嵌入式开发] CE 6 下键盘钩子(HOOK)的实现

//?已经写过一个?CE5.0?下的键盘钩子:http://blog.csdn.net/91program/article/details/1961570 //?前一段时间在坛子看到有人在问?CE6.0?下钩子的实现,有的说不行,有的说行,...

关键字: keyboard hook

[玩儿转嵌入式开发] CE 6 鼠标钩子(HOOK)

//?MouseHook.h? #ifdef?MOUSEHOOK_EXPORTS #define?MOUSEHOOK_API?__declspec(dllexport) #else #define?MOUSEHOOK_API?__decl...

关键字: hook callback

[算法研习社] SKYNET设计综述讲到模块被称为服务

SKYNET设计综述讲到模块被称为服务。“服务间可以自由发送消息。每个模块可以向 Skynet 框架注册一个 callback 函数,用来接收发给它的消息。”还提到“把一个符合规范的 C 模块,从动态库(so 文件)中启动起来,绑定一个永不...

关键字: 函数 框架 callback skynet

玩儿转嵌入式开发

327 篇文章

关注

发布文章

技术子站

更多

论坛活动

  • 加入Vicor,让机器人供电系统设计更有“料”
    加入Vicor,让机器人供电系统设计更有“料”
  • ADI视频课堂精品上新-观看有礼
  • 【20周年庆】21ic下载站VIP五折起,技术资料免积分下载!
  • (有奖活动)贸泽电子设计“新”头好
更多

资料下载

  • 《嵌入式LINUX基础教程》中文 第2版 (2 of 3)
  • 《嵌入式LINUX基础教程》中文 第2版 (3of 3)
  • 《嵌入式LINUX基础教程》中文 第2版 (1 of 3)
  • ST-Link原理图和固件
  • Linux下C语言编程入门教程
  • 基于51单片机数字音乐盒的设计
  • Linux Kernel Developments 内核开发
  • Multisim2001电路设计及仿真教材
  • 基于51系列单片机控制步进电机调速闭环系统设计
  • 新概念模拟电路全集
关闭
XML 地图 | Sitemap 地图