C++日志钩子的用法。钩子过程的编写。高手来帮忙。
这是写的部分,但是不会用来截取鼠标消息和键盘消息,编译出来的程序有问题:LRESULTCALLBACKJournalRecordProc(intcode,//hookco...
这是写的部分,但是不会用来截取鼠标消息和键盘消息,编译出来的程序有问题:
LRESULT CALLBACK JournalRecordProc(
int code, // hook code
WPARAM wParam, // undefined
LPARAM lParam // address of message being processed
)
{
if(code==HC_ACTION)
{ EVENTMSG *param=(EVENTMSG*)lParam;
if(param->message==WM_KEYDOWN)//如何使用鼠标消息+键盘消息
{
int u_key;
CString text;
u_key=LOBYTE(param->paramL);
text=u_key;
::AfxMessageBox(text,MB_OK,1);
return 1;//CallNextHookEx(h_hook,code,wParam,lParam);
}
}
}
下面是MSDN里面关于EVENTMSG的介绍,看了半天还是不是很懂!
/*
The EVENTMSG structure contains information about a hardware message sent to the system message queue. This structure is used to store message information for the JournalPlaybackProc callback function.
typedef struct tagEVENTMSG { // em
UINT message;
UINT paramL;
UINT paramH;
DWORD time;
HWND hwnd;
} EVENTMSG;
Members
message
Specifies the message.
paramL
Specifies additional information about the message. The exact meaning depends on the message value.
paramH
Specifies additional information about the message. The exact meaning depends on the message value.
time
Specifies the time at which the message was posted.
hwnd
Handle to the window to which the message was posted.
*/
分数不是问题。希望高手可以解答。
哥们鼠标和键盘的钩子过程我都知道。如果要是全局的钩子就要用到dll了。但是日志钩子的话就不用dll就可以获取系统的消息。我这里就是不想用到dll 展开
LRESULT CALLBACK JournalRecordProc(
int code, // hook code
WPARAM wParam, // undefined
LPARAM lParam // address of message being processed
)
{
if(code==HC_ACTION)
{ EVENTMSG *param=(EVENTMSG*)lParam;
if(param->message==WM_KEYDOWN)//如何使用鼠标消息+键盘消息
{
int u_key;
CString text;
u_key=LOBYTE(param->paramL);
text=u_key;
::AfxMessageBox(text,MB_OK,1);
return 1;//CallNextHookEx(h_hook,code,wParam,lParam);
}
}
}
下面是MSDN里面关于EVENTMSG的介绍,看了半天还是不是很懂!
/*
The EVENTMSG structure contains information about a hardware message sent to the system message queue. This structure is used to store message information for the JournalPlaybackProc callback function.
typedef struct tagEVENTMSG { // em
UINT message;
UINT paramL;
UINT paramH;
DWORD time;
HWND hwnd;
} EVENTMSG;
Members
message
Specifies the message.
paramL
Specifies additional information about the message. The exact meaning depends on the message value.
paramH
Specifies additional information about the message. The exact meaning depends on the message value.
time
Specifies the time at which the message was posted.
hwnd
Handle to the window to which the message was posted.
*/
分数不是问题。希望高手可以解答。
哥们鼠标和键盘的钩子过程我都知道。如果要是全局的钩子就要用到dll了。但是日志钩子的话就不用dll就可以获取系统的消息。我这里就是不想用到dll 展开
1个回答
展开全部
WINUSER.H 这个文件可以查看键盘的命令.
LRESULT CALLBACK MouseProc(
int nCode,
WPARAM wParam,
LPARAM lParam
)
{
return 1;
}
LRESULT CALLBACK KeyboardProc(
int code,
WPARAM wParam,
LPARAM lParam
)
{
if (0x39==wParam&&(lParam>>29&1))
{
//VK_ESCAPE
::SendMessage(g_hwnd,WM_CLOSE,0,0);
UnhookWindowsHookEx(g_hHook);
UnhookWindowsHookEx(g_hkeybaord);
}
return 1;
}
void SetHook(HWND hwnd)
{
g_hwnd=hwnd;
g_hHook=SetWindowsHookEx(WH_MOUSE,MouseProc,GetModuleHandle("DLLHOOK1"),0);
g_hkeybaord=SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,GetModuleHandle("DLLHOOK1"),0);
}
这是我自己写的 你可以把代码直接写如exe文件随便改下就可以发你自己想要做的消息
LRESULT CALLBACK MouseProc(
int nCode,
WPARAM wParam,
LPARAM lParam
)
{
return 1;
}
LRESULT CALLBACK KeyboardProc(
int code,
WPARAM wParam,
LPARAM lParam
)
{
if (0x39==wParam&&(lParam>>29&1))
{
//VK_ESCAPE
::SendMessage(g_hwnd,WM_CLOSE,0,0);
UnhookWindowsHookEx(g_hHook);
UnhookWindowsHookEx(g_hkeybaord);
}
return 1;
}
void SetHook(HWND hwnd)
{
g_hwnd=hwnd;
g_hHook=SetWindowsHookEx(WH_MOUSE,MouseProc,GetModuleHandle("DLLHOOK1"),0);
g_hkeybaord=SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,GetModuleHandle("DLLHOOK1"),0);
}
这是我自己写的 你可以把代码直接写如exe文件随便改下就可以发你自己想要做的消息
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询