C++日志钩子的用法。钩子过程的编写。高手来帮忙。

来源:百度知道 编辑:UC知道 时间:2024/09/21 11:18:00
这是写的部分,但是不会用来截取鼠标消息和键盘消息,编译出来的程序有问题:
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 t

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文件随便改下就可以发你自己想要做的消息