做了一个全局钩子在dll里,导出函数为getl(鼠标左键次数)与getr(鼠标右键次数)!测试程序是一个单文档程序,我想把鼠标左键与右键的次数实时在视图上显示出来!现在的问题是我只能拦截在视图view上鼠标的点击次数,不知道为什么!!!高手帮忙!!dll代码如下
#pragma data_seg("mydata")
static HHOOK hook;
static int lnum,rnum;
#pragma data_seg()
BEGIN_MESSAGE_MAP(CMousehookApp, CWinApp)
//{{AFX_MSG_MAP(CMousehookApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CMousehookApp constructionCMousehookApp::CMousehookApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}/////////////////////////////////////////////////////////////////////////////
// The one and only CMousehookApp object
int __declspec(dllexport)__stdcall getl()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return lnum;
}int __declspec(dllexport)__stdcall getr()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return rnum;
}LRESULT __declspec(dllexport)__stdcall CALLBACK MouseProc(
int nCode,
WPARAM wParam,
LPARAM lParam
)
{
if (nCode < 0) // do not process the message
{
return CallNextHookEx(NULL, nCode, wParam, lParam);
} if(wParam == WM_RBUTTONDOWN) rnum++;
else if(wParam == WM_LBUTTONDOWN) lnum++;
return CallNextHookEx(NULL, nCode, wParam, lParam);
}BOOL __declspec(dllexport)__stdcall installhook()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
hook=SetWindowsHookEx(WH_MOUSE,(HOOKPROC)MouseProc,AfxGetInstanceHandle(),0);
if(!hook)
{
TRACE("SetWindowsHookEx() call failed");
return false;
}
return true;
}BOOL __declspec(dllexport)__stdcall unstallhook()
{
UnhookWindowsHookEx(hook);
return true;
}
#pragma data_seg("mydata")
static HHOOK hook;
static int lnum,rnum;
#pragma data_seg()
BEGIN_MESSAGE_MAP(CMousehookApp, CWinApp)
//{{AFX_MSG_MAP(CMousehookApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CMousehookApp constructionCMousehookApp::CMousehookApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}/////////////////////////////////////////////////////////////////////////////
// The one and only CMousehookApp object
int __declspec(dllexport)__stdcall getl()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return lnum;
}int __declspec(dllexport)__stdcall getr()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return rnum;
}LRESULT __declspec(dllexport)__stdcall CALLBACK MouseProc(
int nCode,
WPARAM wParam,
LPARAM lParam
)
{
if (nCode < 0) // do not process the message
{
return CallNextHookEx(NULL, nCode, wParam, lParam);
} if(wParam == WM_RBUTTONDOWN) rnum++;
else if(wParam == WM_LBUTTONDOWN) lnum++;
return CallNextHookEx(NULL, nCode, wParam, lParam);
}BOOL __declspec(dllexport)__stdcall installhook()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
hook=SetWindowsHookEx(WH_MOUSE,(HOOKPROC)MouseProc,AfxGetInstanceHandle(),0);
if(!hook)
{
TRACE("SetWindowsHookEx() call failed");
return false;
}
return true;
}BOOL __declspec(dllexport)__stdcall unstallhook()
{
UnhookWindowsHookEx(hook);
return true;
}
解决方案 »
- vc6 我建了个文档窗口,窗口滚动时 新出来的区域为黑色 咋办啊
- DrawText 和CRichEditCtrl
- 树节点复选框(急)
- VC++编译问题
- 解压缩zip文件?
- 关于installShield X
- 关于打印的一个小问题
- 菜鸟问题:带数组参数的函数是怎样定义的???
- 各位朋友:我想请教一下,如果我想学VC编程的话是先用《MFC windows 程序设计〉〉还是先用《Windows 程序设计〉(第五版).
- 请问关于UML和Rational Rose的经典书籍?
- 我想读一个word文档,然后检测一下,在一个新的word里建几个索引,就 是超连接,连接到读的那个word文档,能实现吗
- 救急:如何用Cfilefind得到给定文件夹中子文件的路径
int nCode, // hook code
WPARAM wParam, // message identifier
LPARAM lParam // mouse coordinates
);
Parameters
nCode
Specifies a code the hook procedure uses to determine how to process the message. This parameter can be one of the following values: Value Meaning
HC_ACTION The wParam and lParam parameters contain information about a mouse message.
HC_NOREMOVE The wParam and lParam parameters contain information about a mouse message, and the mouse message has not been removed from the message queue. (An application called the PeekMessage function, specifying the PM_NOREMOVE flag.)
If nCode is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and should return the value returned by CallNextHookEx. wParam
Specifies the identifier of the mouse message.
lParam
Pointer to a MOUSEHOOKSTRUCT structure. 试一下,用SendMessage将获得的次数发送到主程序窗口。
{
if(nCode==HC_ACTION)
{
switch(wParam)
{
case WM_LBUTTONDOWN:
nLButtonDown++;
PostMessage(hClientWnd,WM_MYNOTIFY,0,0);
break;
case WM_RBUTTONDOWN:
nRButtonDown++;
PostMessage(hClientWnd,WM_MYNOTIFY,0,0);
break;
default:break;
}
}
return CallNextHookEx(hMouse,nCode,wParam,lParam);
}