我要用一个钩子,来捕获特定的一个应用程序中的点击某个按钮的事件,当按钮点击的次数超过一定次数后,就不让其再响应这个按钮的事件,
我自己DLL写了钩子,老是有问题,我的思路主要如下,设置一个GETMESSAGE的钩子,在DLL设置一个计数器,每次钩子勾到这个按钮的消息以后,就将计数器加1,当超过了某个次数以后,就不调用CallNextHookEx。
主要代码如下:
LRESULT CALLBACK GetMsgProc(int code,WPARAM wParam,LPARAM lParam)
{
if(code < 0)
{
::MessageBox(NULL,_T("<0必须处理"),_T("提示"),MB_OK);
}
else if(code == HC_ACTION)
{
MSG* pMsg = (MSG*)lParam;
char szBuffer[100];
GetWindowText(pMsg->hwnd,LPWSTR(szBuffer),100);
if(strcmp(szBuffer,"Button") == 0)
{
if(++g_iCount >=5)
{
return 1;
}
}
}
return CallNextHookEx(g_hMsgHook,code,wParam,lParam);}不知道这样行不行,高手请赐教,谢谢!!!!!!!
我自己DLL写了钩子,老是有问题,我的思路主要如下,设置一个GETMESSAGE的钩子,在DLL设置一个计数器,每次钩子勾到这个按钮的消息以后,就将计数器加1,当超过了某个次数以后,就不调用CallNextHookEx。
主要代码如下:
LRESULT CALLBACK GetMsgProc(int code,WPARAM wParam,LPARAM lParam)
{
if(code < 0)
{
::MessageBox(NULL,_T("<0必须处理"),_T("提示"),MB_OK);
}
else if(code == HC_ACTION)
{
MSG* pMsg = (MSG*)lParam;
char szBuffer[100];
GetWindowText(pMsg->hwnd,LPWSTR(szBuffer),100);
if(strcmp(szBuffer,"Button") == 0)
{
if(++g_iCount >=5)
{
return 1;
}
}
}
return CallNextHookEx(g_hMsgHook,code,wParam,lParam);}不知道这样行不行,高手请赐教,谢谢!!!!!!!
解决方案 »
- 请问CListCtrl不是report样式要如何排序?
- 拖动快捷方式的问题
- VC中文件操作的问题(如何控制文件指针如何按行向前移动)
- 为什么我的dll工程编译通过之后没有生成lib文件,只有dll文件?
- 第一次做报表打印软件遇到问题了.
- msvcrtd.lib(crtexew.obj) : error LNK2001: unresolved external symbol _WinMain@16
- 为何wsock32.dll会自动恢复呢?
- 怎样添加一个带图案的ToolBar?
- 帮帮我吧
- 如何在sdk下实现IMediaPlayer2接口。
- vc2003 对话框
- 高手帮忙:我现在能获取到USB的{745A17A0-74D3-11D0-B6FE-00A0C90F57DA}\0003 ,但如果能得到盘符呢,想 "G"," H ",之类的?
{
if(code < 0)
{
::MessageBox(NULL,_T("<0必须处理"),_T("提示"),MB_OK);
}
else if(code == HC_ACTION)
{
//::MessageBox(NULL,_T("action"),_T("提示"),MB_OK);
MSG* pMsg = (MSG*)lParam;
char szBuffer[100];
if(pMsg->hwnd == NULL)
return 1;//运行到这里之后,还是能响应!!!
GetWindowText(pMsg->hwnd,LPWSTR(szBuffer),100);
if(strcmp(szBuffer,"Button") == 0 && pMsg->lParam == NM_CLICK)
{
::MessageBox(NULL,_T("匹配"),_T("提示"),MB_OK);
if(++g_iCount >=5)
{
::MessageBox(NULL,_T("次数超限"),_T("提示"),MB_OK);
return 1;
}
}
}
return CallNextHookEx(g_hMsgHook,code,wParam,lParam);}
在MSDN中查到的!LRESULT CALLBACK GetMsgProc( int code,
WPARAM wParam,
LPARAM lParam
);
Parameterscode
[in] Specifies whether the hook procedure must process the message. If code is HC_ACTION, the hook procedure must process the message. If code 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//这个参数??????
[in] Specifies whether the message has been removed from the queue. This parameter can be one of the following values.
PM_NOREMOVE
Specifies that the message has not been removed from the queue. (An application called the PeekMessage function, specifying the PM_NOREMOVE flag.)
PM_REMOVE
Specifies that the message has been removed from the queue. (An application called GetMessage, or it called the PeekMessage function, specifying the PM_REMOVE flag.)
lParam
[in] Pointer to an MSG structure that contains details about the message.
是不是消息被勾住了之后,由于消息还是没有移除消息队列,所以,处理过程还是被调用了??
void CMyHook::SetMessageHook()
{
g_hMsgHook = SetWindowsHookEx(WH_GETMESSAGE,GetMsgProc,NULL,::GetCurrentThreadId());
if(g_hMsgHook == NULL)
{
::MessageBox(NULL,_T("装载钩子失败"),_T("提示"),MB_OK);
}}
int idHook, //装载的钩子的类型
HOOKPROC lpfn, //钩子回调函数的地址,dwThreadId为0回调函数会在不同的进程中创建,它必须写在DLL中
HINSTANCE hMod, //DLL的句柄
DWORD dwThreadId //描述要钩住的线程ID,如果参数为0,会钩住桌面上的所有线程!
); //若函数调用成功,返回值是成功开启的钩子句柄,如果失败,返回值为0!
LRESULT CALLBACK GetMsgProc(
int code, //nCode == HC_ACTION,钩子程序处理这个消息,如果nCode 的值小于零,则跳过这个消息
WPARAM wParam, //这个消息是否从消息队列中被删除,值为:PM_NOREMOVE(应用程序调用了PeekMessage)
//PM_REMOVE :描述这个消息已经从消息队列中删除(应用程序调用了 GetMessage 或 PeekMessage)
LPARAM lParam //MSG 结构体的指针
);
不懂了!!!郁闷!!
if(strcmp(szBuffer,"Button") == 0 && pMsg->lParam == NM_CLICK)
{
::MessageBox(NULL,_T("匹配"),_T("提示"),MB_OK);
if(++g_iCount >=5)
{
::MessageBox(NULL,_T("次数超限"),_T("提示"),MB_OK);
return 1;
}
}
高手帮忙看看,哪里有问题???或者是问题出在哪里???