分享
 
 
 

WH_JOURNALRECORD与WH_JOURNALPLAYBACK应用(记录和回放)

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

/*****************HOOKService.h***********************/

BOOL InstallOperationsHook(HWND,HINSTANCE);

BOOL InstallOperationsDisplayHook(HWND,HINSTANCE);

BOOL UnInstallOperationsHook();

BOOL UnInstallOperationsDisplayHook();

BOOL CheckOperationsRecordHookHandle();

BOOL CheckOperationsDisplayHookHandle();

LRESULT CALLBACK JournalPlaybackProc(int,WPARAM,LPARAM);

LRESULT CALLBACK JournalRecordProc(int,WPARAM,LPARAM);

LPCTSTR GetMsgName(UINT);

void FreeMsgList();

/*****************HOOKService.h***********************/

/*****************HOOKService.cpp***********************/

#include "stdafx.h"

#include "HOOKService.h"

BOOL InstallOperationsHook(HWND hWnd,HINSTANCE hInst)

{

if (!UnInstallOperationsDisplayHook())

return FALSE;

if (CheckOperationsRecordHookHandle())

return TRUE;

g_AppInstance = hInst;

g_Dlg_Hwnd = hWnd;

FreeMsgList();

g_hHookOperationsRecord = ::SetWindowsHookEx(WH_JOURNALRECORD,

JournalRecordProc,

g_AppInstance,

0);

return g_hHookOperationsRecord ? TRUE : FALSE;

}

BOOL InstallOperationsDisplayHook(HWND hWnd,HINSTANCE hInst)

{

if (!UnInstallOperationsHook())

return FALSE;

if (CheckOperationsDisplayHookHandle())

return TRUE;

g_AppInstance = hInst;

g_Dlg_Hwnd = hWnd;

g_pMsgListPrev = g_pMsgMovePtr = g_pMsgListLast = NULL;

RetTime = 0;

g_hHookOperationsDisplay = ::SetWindowsHookEx(WH_JOURNALPLAYBACK,

JournalPlaybackProc,

g_AppInstance,

0);

return g_hHookOperationsDisplay ? TRUE : FALSE;

}

LRESULT CALLBACK JournalRecordProc(int nCode,WPARAM wParam,LPARAM lParam)

{

if (nCode < 0)

return ::CallNextHookEx(g_hHookOperationsRecord,nCode,wParam,lParam);

if (nCode == HC_ACTION)

{

MsgList* pTmpMsgList = new MsgList;

pTmpMsgList->Event.hwnd = ((LPEVENTMSG)lParam)->hwnd;

pTmpMsgList->Event.message = ((LPEVENTMSG)lParam)->message;

pTmpMsgList->Event.paramH = ((LPEVENTMSG)lParam)->paramH;

pTmpMsgList->Event.paramL = ((LPEVENTMSG)lParam)->paramL;

pTmpMsgList->Event.time = ((LPEVENTMSG)lParam)->time;

if (!g_pMsgMovePtr)

{

if (!g_pMsgListHeader)

g_pMsgListPrev = g_pMsgListHeader = g_pMsgMovePtr = pTmpMsgList;

}

else

{

g_pMsgListLast = pTmpMsgList;/*将新消息作为最后的消息*/

g_pMsgListPrev = g_pMsgMovePtr;/*保存上次的消息*/

g_pMsgMovePtr->lpNext = pTmpMsgList;/*将新消息挂到消息列表*/

g_pMsgMovePtr = pTmpMsgList;/*将实时指针指向最后的消息*/

}

::PostMessage(g_Dlg_Hwnd,WM_PASSDATA,wParam,(LPARAM)pTmpMsgList);

}

return ::CallNextHookEx(g_hHookOperationsRecord,nCode,wParam,lParam);

}

LRESULT CALLBACK JournalPlaybackProc(int nCode,WPARAM wParam,LPARAM lParam)

{

if (nCode < 0)

return ::CallNextHookEx(g_hHookOperationsDisplay,nCode,wParam,lParam);

if (!g_pMsgMovePtr)

{

if (!g_pMsgListHeader)

{

return UnInstallOperationsDisplayHook();

}

g_pMsgMovePtr = g_pMsgListHeader;

g_pMsgListPrev = g_pMsgListHeader;

}

switch (nCode)

{

case HC_GETNEXT:

/*********************************************************************

*The hook procedure must copy the current mouse or keyboard message *

*to the EVENTMSG structure pointed to by the lParam parameter. *

*********************************************************************/

{

LPEVENTMSG lpEvent = (LPEVENTMSG)lParam;

if (g_pMsgMovePtr && g_pMsgListPrev && lpEvent)

{

lpEvent->message = g_pMsgListPrev->Event.message;

lpEvent->paramL = g_pMsgListPrev->Event.paramL;

lpEvent->paramH = g_pMsgListPrev->Event.paramH;

lpEvent->time = g_pMsgListPrev->Event.time;

lpEvent->hwnd = g_pMsgListPrev->Event.hwnd;

RetTime = g_pMsgMovePtr->Event.time - g_pMsgListPrev->Event.time;

if (g_pMsgMovePtr != g_pMsgListPrev)

{

g_pMsgListPrev = g_pMsgMovePtr;

}

}

if (RetTime < 0)

RetTime = 1;

return RetTime;

}

case HC_SKIP:

/*****************************************************************************

*The hook procedure must prepare to copy the next mouse or keyboard message *

*to the EVENTMSG structure pointed to by lParam. *

*Upon receiving the HC_GETNEXT code, *

*the hook procedure must copy the message to the structure. *

*****************************************************************************/

{

if (!g_pMsgMovePtr->lpNext)

{

return UnInstallOperationsDisplayHook();

}

if (g_pMsgListPrev != g_pMsgMovePtr)

g_pMsgListPrev = g_pMsgMovePtr;

g_pMsgMovePtr = g_pMsgMovePtr->lpNext;

return 0;

}

default:

break;

}

return ::CallNextHookEx(g_hHookOperationsDisplay,nCode,wParam,lParam);

}

BOOL CheckOperationsRecordHookHandle()

{

return g_hHookOperationsRecord ? TRUE : FALSE;

}

BOOL CheckOperationsDisplayHookHandle()

{

return g_hHookOperationsDisplay ? TRUE : FALSE;

}

BOOL UnInstallOperationsHook()

{

if (!g_hHookOperationsRecord)

return TRUE;

BOOL IsUnInstallSuccess = ::UnhookWindowsHookEx(g_hHookOperationsRecord);

g_hHookOperationsRecord = NULL;

return IsUnInstallSuccess;

}

BOOL UnInstallOperationsDisplayHook()

{

if (!g_hHookOperationsDisplay)

return TRUE;

BOOL IsUnInstallSuccess = ::UnhookWindowsHookEx(g_hHookOperationsDisplay);

g_hHookOperationsDisplay = NULL;

return IsUnInstallSuccess;

}

LPCTSTR GetMsgName(UINT nCode)

{

for(int i=0,nCount=sizeof(messages)/sizeof(MsgStruct);i<nCount;++i)

{

if(messages[i].nCode == nCode)

return messages[i].pszText;

}

return "Sorry,I Don't Know.";

}

void FreeMsgList()

{

delete g_pMsgListHeader;

g_pMsgMovePtr = NULL;

g_pMsgListHeader = NULL;

g_pMsgListLast = NULL;

g_pMsgListPrev = NULL;

RetTime = 0;

}

/*****************HOOKService.cpp***********************/

/*****************stdafx.h***********************/

// stdafx.h : 标准系统包含文件的包含文件,

// 或是经常使用但不常更改的

// 项目特定的包含文件

#pragma once

#ifndef VC_EXTRALEAN

#define VC_EXTRALEAN // 从 Windows 标头中排除不常使用的资料

#endif

// 如果您必须使用下列所指定的平台之前的平台,则修改下面的定义。

// 有关不同平台的相应值的最新信息,请参考 MSDN。

#ifndef WINVER //允许使用 Windows 95 和 Windows NT 4 或更高版本的特定功能。

#define WINVER 0x0400 //为 Windows98 和 Windows 2000 及更新版本改变为适当的值。

#endif

#ifndef _WIN32_WINNT // 允许使用 Windows NT 4 或更高版本的特定功能。

#define _WIN32_WINNT 0x0400 //为 Windows98 和 Windows 2000 及更新版本改变为适当的值。

#endif

#ifndef _WIN32_WINDOWS // 允许使用 Windows 98 或更高版本的特定功能。

#define _WIN32_WINDOWS 0x0410 //为 Windows Me 及更新版本改变为适当的值。

#endif

#ifndef _WIN32_IE //允许使用 IE 4.0 或更高版本的特定功能。

#define _WIN32_IE 0x0400 //为 IE 5.0 及更新版本改变为适当的值。

#endif

#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的

// 关闭 MFC 对某些常见但经常被安全忽略的警告消息的隐藏

#define _AFX_ALL_WARNINGS

#include <afxwin.h> // MFC 核心和标准组件

#include <afxext.h> // MFC 扩展

#include <afxdisp.h> // MFC 自动化类

#include <afxdtctl.h> // Internet Explorer 4 公共控件的 MFC 支持

#ifndef _AFX_NO_AFXCMN_SUPPORT

#include <afxcmn.h>// Windows 公共控件的 MFC 支持

#endif // _AFX_NO_AFXCMN_SUPPORT

#define WM_PASSDATA WM_USER+1982

#include <vector>

using namespace std;

#include <windowsx.h>

#include <winable.h>

struct MsgStruct

{

UINT nCode;

LPCTSTR pszText;

};

struct MsgList

{

public:

MsgList()

{

memset(&Event,0,sizeof(EVENTMSG));

lpNext = NULL;

}

~MsgList()

{

if (lpNext && !::IsBadReadPtr(lpNext,sizeof(MsgList)))

delete lpNext;

memset(&Event,0,sizeof(EVENTMSG));

lpNext = NULL;

}

EVENTMSG Event;

MsgList *lpNext;

};

static HHOOK g_hHookOperationsRecord = NULL;

static HHOOK g_hHookOperationsDisplay = NULL;

static HINSTANCE g_AppInstance = NULL;

static MsgList* g_pMsgMovePtr = NULL;

static MsgList* g_pMsgListHeader = NULL;

static MsgList* g_pMsgListLast = NULL;

static MsgList* g_pMsgListPrev = NULL;

static HWND g_Dlg_Hwnd = NULL;

static DWORD RetTime = 0;

static MsgStruct messages[] = {

{WM_NULL,"WM_NULL"},

{WM_CREATE,"WM_CREATE"},

{WM_DESTROY,"WM_DESTROY"},

{WM_MOVE,"WM_MOVE"},

{WM_SIZE,"WM_SIZE"},

{WM_ACTIVATE,"WM_ACTIVATE"},

{WM_SETFOCUS,"WM_SETFOCUS"},

{WM_KILLFOCUS,"WM_KILLFOCUS"},

{WM_ENABLE,"WM_ENABLE"},

{WM_SETREDRAW,"WM_SETREDRAW"},

{WM_SETTEXT,"WM_SETTEXT"},

{WM_GETTEXT,"WM_GETTEXT"},

{WM_GETTEXTLENGTH,"WM_GETTEXTLENGTH"},

{WM_PAINT,"WM_PAINT"},

{WM_CLOSE,"WM_CLOSE"},

{WM_QUERYENDSESSION,"WM_QUERYENDSESSION"},

{WM_QUIT,"WM_QUIT"},

{WM_QUERYOPEN,"WM_QUERYOPEN"},

{WM_ERASEBKGND,"WM_ERASEBKGND"},

{0x0015,"WM_SYSCOLORCHANGE"},

{WM_ENDSESSION,"WM_ENDSESSION"},

{WM_SHOWWINDOW,"WM_SHOWWINDOW"},

{WM_WININICHANGE,"WM_WININICHANGE"},

{WM_DEVMODECHANGE,"WM_DEVMODECHANGE"},

{WM_ACTIVATEAPP,"WM_ACTIVATEAPP"},

{0x001D,"WM_FONTCHANGE"},

{WM_TIMECHANGE,"WM_TIMECHANGE"},

{WM_CANCELMODE,"WM_CANCELMODE"},

{WM_SETCURSOR,"WM_SETCURSOR"},

{WM_MOUSEACTIVATE,"WM_MOUSEACTIVATE"},

{WM_CHILDACTIVATE,"WM_CHILDACTIVATE"},

{WM_QUEUESYNC,"WM_QUEUESYNC"},

{WM_GETMINMAXINFO,"WM_GETMINMAXINFO"},

{WM_ICONERASEBKGND,"WM_ICONERASEBKGND"},

{WM_NEXTDLGCTL,"WM_NEXTDLGCTL"},

{WM_SPOOLERSTATUS,"WM_SPOOLERSTATUS"},

{WM_DRAWITEM,"WM_DRAWITEM"},

{WM_MEASUREITEM,"WM_MEASUREITEM"},

{WM_DELETEITEM,"WM_DELETEITEM"},

{WM_VKEYTOITEM,"WM_VKEYTOITEM"},

{WM_CHARTOITEM,"WM_CHARTOITEM"},

{WM_SETFONT,"WM_SETFONT"},

{WM_GETFONT,"WM_GETFONT"},

{WM_QUERYDRAGICON,"WM_QUERYDRAGICON"},

{WM_COMPAREITEM,"WM_COMPAREITEM"},

{WM_COMPACTING,"WM_COMPACTING"},

{0x0044,"WM_COMMNOTIFY"},

{WM_WINDOWPOSCHANGING,"WM_WINDOWPOSCHANGING"},

{WM_WINDOWPOSCHANGED,"WM_WINDOWPOSCHANGED"},

{WM_POWER, "WM_POWER"},

{WM_NCCREATE,"WM_NCCREATE"},

{WM_NCDESTROY,"WM_NCDESTROY"},

{WM_NCCALCSIZE,"WM_NCCALCSIZE"},

{WM_NCHITTEST,"WM_NCHITTEST"},

{WM_NCPAINT, "WM_NCPAINT"},

{WM_NCACTIVATE,"WM_NCACTIVATE"},

{WM_GETDLGCODE,"WM_GETDLGCODE"},

{WM_NCMOUSEMOVE,"WM_NCMOUSEMOVE"},

{WM_NCLBUTTONDOWN,"WM_NCLBUTTONDOWN"},

{WM_NCLBUTTONUP,"WM_NCLBUTTONUP"},

{WM_NCLBUTTONDBLCLK,"WM_NCLBUTTONDBLCLK"},

{WM_NCRBUTTONDOWN,"WM_NCRBUTTONDOWN"},

{WM_NCRBUTTONUP,"WM_NCRBUTTONUP"},

{WM_NCRBUTTONDBLCLK,"WM_NCRBUTTONDBLCLK"},

{WM_NCMBUTTONDOWN,"WM_NCMBUTTONDOWN"},

{WM_NCMBUTTONUP,"WM_NCMBUTTONUP"},

{WM_NCMBUTTONDBLCLK,"WM_NCMBUTTONDBLCLK"},

{WM_KEYDOWN,"WM_KEYDOWN"},

{WM_KEYUP, "WM_KEYUP"},

{WM_CHAR,"WM_CHAR"},

{WM_DEADCHAR,"WM_DEADCHAR"},

{WM_SYSKEYDOWN,"WM_SYSKEYDOWN"},

{WM_SYSKEYUP,"WM_SYSKEYUP"},

{WM_SYSCHAR,"WM_SYSCHAR"},

{WM_SYSDEADCHAR,"WM_SYSDEADCHAR"},

{WM_KEYLAST,"WM_KEYLAST"},

{WM_INITDIALOG,"WM_INITDIALOG"},

{WM_COMMAND,"WM_COMMAND"},

{WM_SYSCOMMAND,"WM_SYSCOMMAND"},

{WM_TIMER, "WM_TIMER"},

{0x0114,"WM_HSCROLL"},

{0x0115,"WM_VSCROLL"},

{WM_INITMENU,"WM_INITMENU"},

{WM_INITMENUPOPUP,"WM_INITMENUPOPUP"},

{WM_MENUSELECT,"WM_MENUSELECT"},

{WM_MENUCHAR,"WM_MENUCHAR"},

{WM_ENTERIDLE,"WM_ENTERIDLE"},

{WM_MOUSEMOVE,"WM_MOUSEMOVE"},

{WM_LBUTTONDOWN,"WM_LBUTTONDOWN"},

{WM_LBUTTONUP,"WM_LBUTTONUP"},

{WM_LBUTTONDBLCLK,"WM_LBUTTONDBLCLK"},

{WM_RBUTTONDOWN,"WM_RBUTTONDOWN"},

{WM_RBUTTONUP,"WM_RBUTTONUP"},

{WM_RBUTTONDBLCLK,"WM_RBUTTONDBLCLK"},

{WM_MBUTTONDOWN,"WM_MBUTTONDOWN"},

{WM_MBUTTONUP,"WM_MBUTTONUP"},

{WM_MBUTTONDBLCLK,"WM_MBUTTONDBLCLK"},

{WM_PARENTNOTIFY,"WM_PARENTNOTIFY"},

{WM_MDICREATE,"WM_MDICREATE"},

{WM_MDIDESTROY,"WM_MDIDESTROY"},

{WM_MDIACTIVATE,"WM_MDIACTIVATE"},

{WM_MDIRESTORE,"WM_MDIRESTORE"},

{WM_MDINEXT,"WM_MDINEXT"},

{WM_MDIMAXIMIZE,"WM_MDIMAXIMIZE"},

{WM_MDITILE,"WM_MDITILE"},

{WM_MDICASCADE,"WM_MDICASCADE"},

{WM_MDIICONARRANGE,"WM_MDIICONARRANGE"},

{WM_MDIGETACTIVE,"WM_MDIGETACTIVE"},

{WM_MDISETMENU,"WM_MDISETMENU"},

{WM_DROPFILES,"WM_DROPFILES"},

{WM_CUT,"WM_CUT"},

{WM_COPY,"WM_COPY"},

{WM_PASTE,"WM_PASTE"},

{WM_CLEAR,"WM_CLEAR"},

{WM_UNDO,"WM_UNDO"},

{WM_RENDERFORMAT,"WM_RENDERFORMAT"},

{WM_RENDERALLFORMATS,"WM_RENDERALLFORMATS"},

{WM_DESTROYCLIPBOARD,"WM_DESTROYCLIPBOARD"},

{WM_DRAWCLIPBOARD,"WM_DRAWCLIPBOARD"},

{WM_PAINTCLIPBOARD,"WM_PAINTCLIPBOARD"},

{WM_VSCROLLCLIPBOARD,"WM_VSCROLLCLIPBOARD"},

{WM_SIZECLIPBOARD,"WM_SIZECLIPBOARD"},

{WM_ASKCBFORMATNAME,"WM_ASKCBFORMATNAME"},

{WM_CHANGECBCHAIN,"WM_CHANGECBCHAIN"},

{WM_HSCROLLCLIPBOARD,"WM_HSCROLLCLIPBOARD"},

{0x030F,"WM_QUERYNEWPALETTE"},

{0x0310,"WM_PALETTEISCHANGING"},

{0x0311,"WM_PALETTECHANGED"},

{WM_PENWINFIRST,"WM_PENWINFIRST"},

{WM_PENWINLAST,"WM_PENWINLAST"}

};

/*****************stdafx.h***********************/

/*****************MessageTipDlg.h***********************/

// MessageTipDlg.h : 头文件

//

#pragma once

#include "afxcmn.h"

// CMessageTipDlg 对话框

class CMessageTipDlg : public CDialog

{

// 构造

public:

CMessageTipDlg(CWnd* pParent = NULL); // 标准构造函数

// 对话框数据

enum { IDD = IDD_MESSAGETIP_DIALOG };

protected:

virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持

// 实现

protected:

HICON m_hIcon;

// 生成的消息映射函数

virtual BOOL OnInitDialog();

afx_msg void OnPaint();

afx_msg HCURSOR OnQueryDragIcon();

DECLARE_MESSAGE_MAP()

public:

afx_msg void OnBnClickedButtonStart();

afx_msg void OnBnClickedButtonDisplay();

afx_msg void OnBnClickedButtonExit();

afx_msg void OnOK();

afx_msg void OnCancel();

afx_msg void OnClose();

afx_msg LRESULT OnPassData(WPARAM,LPARAM);

private:

void EnableDisplayFunction(BOOL = TRUE);

void EnableStartRecordFunction(BOOL = TRUE);

CListCtrl m_ListCtrl_MsgTip;

CImageList m_ImageList;

CFile m_FileOut;

void InitListCtrl();

protected:

virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);

public:

virtual BOOL PreTranslateMessage(MSG* pMsg);

virtual BOOL DestroyWindow();

afx_msg void OnBnClickedButtonOpenrecord();

afx_msg void OnBnClickedButtonSaverecord();

};

/*****************MessageTipDlg.h***********************/

/*****************MessageTipDlg.cpp***********************/

// MessageTipDlg.cpp : 实现文件

//

#include "stdafx.h"

#include "MessageTip.h"

#include "MessageTipDlg.h"

#include "HOOKService.h"

#include ".\messagetipdlg.h"

#ifdef _DEBUG

#define new DEBUG_NEW

#endif

// CMessageTipDlg 对话框

CMessageTipDlg::CMessageTipDlg(CWnd* pParent /*=NULL*/)

: CDialog(CMessageTipDlg::IDD, pParent)

{

m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

void CMessageTipDlg::DoDataExchange(CDataExchange* pDX)

{

CDialog::DoDataExchange(pDX);

DDX_Control(pDX, IDC_LIST_MSGTIP, m_ListCtrl_MsgTip);

}

BEGIN_MESSAGE_MAP(CMessageTipDlg, CDialog)

ON_WM_PAINT()

ON_WM_QUERYDRAGICON()

//}}AFX_MSG_MAP

ON_BN_CLICKED(ID_BUTTON_START, OnBnClickedButtonStart)

ON_BN_CLICKED(ID_BUTTON_DISPLAY, OnBnClickedButtonDisplay)

ON_BN_CLICKED(ID_BUTTON_EXIT, OnBnClickedButtonExit)

ON_MESSAGE(WM_PASSDATA,OnPassData)

// ON_WM_SIZE()

ON_BN_CLICKED(ID_BUTTON_OPENRECORD, OnBnClickedButtonOpenrecord)

ON_BN_CLICKED(ID_BUTTON_SAVERECORD, OnBnClickedButtonSaverecord)

END_MESSAGE_MAP()

// CMessageTipDlg 消息处理程序

BOOL CMessageTipDlg::OnInitDialog()

{

CDialog::OnInitDialog();

// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动

// 执行此操作

SetIcon(m_hIcon, TRUE); // 设置大图标

SetIcon(m_hIcon, TRUE); // 设置小图标

// TODO: 在此添加额外的初始化代码

EnableDisplayFunction(FALSE);

m_ImageList.Create(16,16,ILC_COLOR32,1,1);

// m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_MSGNAME));

// m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_MSGTIME));

// m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_MSGPARAM));

m_ImageList.Add(m_hIcon);

InitListCtrl();

return TRUE; // 除非设置了控件的焦点,否则返回 TRUE

}

// 如果向对话框添加最小化按钮,则需要下面的代码

// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,

// 这将由框架自动完成。

void CMessageTipDlg::OnPaint()

{

if (IsIconic())

{

CPaintDC dc(this); // 用于绘制的设备上下文

SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

// 使图标在工作矩形中居中

int cxIcon = GetSystemMetrics(SM_CXICON);

int cyIcon = GetSystemMetrics(SM_CYICON);

CRect rect;

GetClientRect(&rect);

int x = (rect.Width() - cxIcon + 1) / 2;

int y = (rect.Height() - cyIcon + 1) / 2;

// 绘制图标

dc.DrawIcon(x, y, m_hIcon);

}

else

{

CDialog::OnPaint();

}

}

//当用户拖动最小化窗口时系统调用此函数取得光标显示。

HCURSOR CMessageTipDlg::OnQueryDragIcon()

{

return static_cast<HCURSOR>(m_hIcon);

}

void CMessageTipDlg::OnBnClickedButtonStart()

{

// TODO: Add your control notification handler code here

CFileDialog CommonFileDlg(FALSE,_T("hook"),_T("消息保存文件"));

if (m_FileOut.m_hFile == INVALID_HANDLE_VALUE)

{

if (CommonFileDlg.DoModal() != IDOK)

{

AfxMessageBox("请选择消息保存位置^_^");

return ;

}

CFileFind FindFind;

if (FindFind.FindFile((LPCTSTR)CommonFileDlg.GetPathName(),0))

m_FileOut.Open((LPCTSTR)CommonFileDlg.GetPathName(),CFile::modeReadWrite);

else

m_FileOut.Open((LPCTSTR)CommonFileDlg.GetPathName(),CFile::modeCreate|CFile::modeReadWrite);

}

else

m_FileOut.SeekToBegin();

ULONGLONG ulFileLength = m_FileOut.GetLength();

if (ulFileLength > 0xffff)

{

m_FileOut.Close();

CString cstrNewFile(_T(""));

cstrNewFile.Format("%s%I64d",CommonFileDlg.GetPathName(),rand() % ulFileLength);

CFileFind FindFind;

if (FindFind.FindFile((LPCTSTR)cstrNewFile,0))

m_FileOut.Open((LPCTSTR)cstrNewFile,CFile::modeReadWrite);

else

m_FileOut.Open((LPCTSTR)cstrNewFile,CFile::modeCreate|CFile::modeReadWrite);

}

if (!InstallOperationsHook(m_hWnd,

AfxGetApp()->m_hInstance))

{

AfxMessageBox("安装系统钩子失败!");

}

EnableStartRecordFunction(FALSE);

EnableDisplayFunction();

}

void CMessageTipDlg::OnBnClickedButtonDisplay()

{

// TODO: Add your control notification handler code here

if (!InstallOperationsDisplayHook(m_hWnd,

AfxGetApp()->m_hInstance))

{

AfxMessageBox("安装系统钩子失败!");

}

EnableStartRecordFunction();

EnableDisplayFunction(FALSE);

}

void CMessageTipDlg::OnBnClickedButtonExit()

{

// TODO: Add your control notification handler code here

FreeMsgList();

UnInstallOperationsHook();

UnInstallOperationsDisplayHook();

CDialog::OnOK();

}

void CMessageTipDlg::OnOK()

{

return ;

}

void CMessageTipDlg::OnCancel()

{

return ;

}

void CMessageTipDlg::OnClose()

{

return ;

}

void CMessageTipDlg::EnableDisplayFunction(BOOL IsEnable/* = TRUE */)

{

((CButton*)GetDlgItem(ID_BUTTON_DISPLAY))->EnableWindow(IsEnable);

}

void CMessageTipDlg::EnableStartRecordFunction(BOOL IsEnable/* = TRUE */)

{

((CButton*)GetDlgItem(ID_BUTTON_START))->EnableWindow(IsEnable);

}

void CMessageTipDlg::InitListCtrl()

{

g_AppInstance = AfxGetApp()->m_hInstance;

m_ListCtrl_MsgTip.SetImageList(&m_ImageList,LVSIL_SMALL);

LVCOLUMN col;

col.mask = LVCF_FMT|LVCF_IMAGE|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH;

col.fmt = LVCFMT_CENTER|LVCFMT_IMAGE;

col.iImage = 0;

col.cchTextMax = ::lstrlen("消息名称")+1;

col.pszText = "消息名称";

col.iSubItem = 0;

CRect rect(0,0,0,0);

m_ListCtrl_MsgTip.GetWindowRect(&rect);

col.cx = 120;

m_ListCtrl_MsgTip.InsertColumn(0,&col);

col.cx = 120;

col.cchTextMax = ::lstrlen("消息值")+1;

col.pszText = "消息值";

m_ListCtrl_MsgTip.InsertColumn(1,&col);

col.cx = rect.Width();

col.cchTextMax = ::lstrlen("消息时间")+1;

col.pszText = "消息时间";

m_ListCtrl_MsgTip.InsertColumn(2,&col);

}

LRESULT CMessageTipDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)

{

// TODO: Add your specialized code here and/or call the base class

return CDialog::WindowProc(message, wParam, lParam);

}

BOOL CMessageTipDlg::PreTranslateMessage(MSG* pMsg)

{

// TODO: Add your specialized code here and/or call the base class

return CDialog::PreTranslateMessage(pMsg);

}

LRESULT CMessageTipDlg::OnPassData(WPARAM wParam,LPARAM lParam)

{

LPEVENTMSG lpEventMsg = (LPEVENTMSG)lParam;

CString cstrMsg(_T(""));

TCHAR TargetWindowName[MAX_PATH] = { '\0' };

::GetWindowText(::GetActiveWindow(),TargetWindowName,MAX_PATH);

COleDateTime cdt(COleDateTime::GetCurrentTime());

CString cstrMsgName(GetMsgName(lpEventMsg->message));

cstrMsg.Format("消息名称:%s\r\n消息目标窗体:%s\r\n消息发送时间:%s\r\n---------------------------------------------\r\n",

cstrMsgName,TargetWindowName,

cdt.Format("%Y年%m月%d日%H时%M分%S秒"));

m_FileOut.Write((LPCTSTR)cstrMsg,cstrMsg.GetLength());

m_ListCtrl_MsgTip.DeleteAllItems();

m_ListCtrl_MsgTip.InsertItem(0,(LPCTSTR)cstrMsgName,0);

m_ListCtrl_MsgTip.SetItemText(0,1,(LPCTSTR)TargetWindowName);

m_ListCtrl_MsgTip.SetItemText(0,2,(LPCTSTR)cdt.Format("%Y年%m月%d日%H时%M分%S秒"));

return 0;

}

BOOL CMessageTipDlg::DestroyWindow()

{

// TODO: Add your specialized code here and/or call the base class

if (m_FileOut.m_hFile != INVALID_HANDLE_VALUE)

m_FileOut.Close();

return CDialog::DestroyWindow();

}

void CMessageTipDlg::OnBnClickedButtonOpenrecord()

{

// TODO: Add your control notification handler code here

}

void CMessageTipDlg::OnBnClickedButtonSaverecord()

{

// TODO: Add your control notification handler code here

}

/*****************MessageTipDlg.cpp***********************/

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有