WINCE6 鼠标全局钩子 响应很慢 求解答原因
本帖最后由 harkue 于 2012-09-08 16:43:22 编辑 参考http://blog.csdn.net/91program/article/details/7162896
做一个CE6 平台上的屏保程序,需要记录鼠标最后点击时间。
但是加载DLL 之后,系统响应奇慢无比!
不知道原因在哪里,求解答
代码如下
// MouseHook.cpp : 定义 DLL 应用程序的入口点。
//
#include "stdafx.h"
#include "MouseHook.h"
#include <windows.h>
#include <commctrl.h>
#include "pwinuser.h"
// 告诉编译器将变量放入它自己的数据共享节中
#pragma data_seg("MouseHookData")
HINSTANCE ghInst = NULL;
HHOOK ghMouseHook = NULL;
//用于记录鼠标最后点击的时间
DWORD gdwLastOperTime = 0;
#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)
{
if(ghInst)
ghMouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProc, ghInst, 0);
}
extern "C" MOUSEHOOK_API void UnMouseHook(void)
{
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)
{
if(nCode < 0) CallNextHookEx(ghMouseHook, nCode, wParam, lParam);
if(wParam == WM_LBUTTONDOWN)//鼠标按下,即记录最后点击时间
gdwLastOperTime = pMouseHookStruct->time;
return CallNextHookEx(ghMouseHook, nCode, wParam, lParam);
}
extern "C" MOUSEHOOK_API DWORD GetLastOperTime()
{
return gdwLastOperTime;
}
extern "C" MOUSEHOOK_API void SetLastOperTime(DWORD dwLastOperTime)
{
gdwLastOperTime = dwLastOperTime;
}