用钩子实现对当前操作的记录,回放,并记录文件

该博客介绍了如何使用C++通过WH_JOURNALRECORD和WH_JOURNALPLAYBACK钩子来记录并回放用户的键盘和鼠标事件。通过创建对话框,设置钩子,记录事件到文件,并从文件加载事件进行回放。
摘要由CSDN通过智能技术生成
// HookTest.cpp : Defines the entry point for the application.
//


#include "stdafx.h"


BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
LRESULT CALLBACK JournalRecordProc(int code,WPARAM wParam,LPARAM lParam);
LRESULT CALLBACK JournalPlaybackProc(int code,WPARAM wParam,LPARAM lParam);
void Clear();


HINSTANCE g_hInst;
HHOOK g_Record;
HHOOK g_Play;


HWND g_hWnd;


int g_nCount = 0;
int g_nCount1 = 0;
int g_nCount2 = 0;


struct EVENTMSG_NODE
{
EVENTMSG msg;
EVENTMSG_NODE *pNext;
};


EVENTMSG_NODE *g_pHead = NULL;
EVENTMSG_NODE *g_pEnd = NULL;


EVENTMSG_NODE *g_pLast;
EVENTMSG_NODE *g_pNext;


int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
  // TODO: Place code here.


g_hInst = hInstance;
HWND hWnd = CreateDialog(hInstance,MAKEINTRESOURCE(IDD_HOOK),NULL,DialogProc);
ShowWindow(hWnd,SW_SHOW);


MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}


BOOL CALLBACK DialogProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
{
g_hWnd = hWnd;
EnableWindow(GetDlgItem(hWnd, IDC_STOP),FALSE);
EnableWindow(GetDlgItem(hWnd, IDC_PLAY),FALSE);
EnableWindow(GetDlgItem(hWnd, IDC_RECORD),TRUE);
EnableWindow(GetDlgItem(hWnd, IDC_SAVE),FALSE);
EnableWindow(GetDlgItem(hWnd, IDC_LOAD),TRUE);
}
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
case WM_COMMAND:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值