一个简单的关于鼠标移动的消息钩子代码 全局消息钩子是病毒吗

MFCDll.h

#ifdef __cplusplus
#define DLLEXPORT extern "C" __declspec (dllexport)
#else
#define DLLEXPORT __declspec (dllexport)
#endif

DLLEXPORT int CALLBACK InstallHOOK();
DLLEXPORT int CALLBACK UninstallHOOK();
DLLEXPORT int CALLBACK GetPos();

MFCDll.cpp

// MFCDll.cpp : Defines the initialization routines for theDLL.
//

#include "stdafx.h"
#include <afxdllx.h>
#include "MFCDll.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//声明一个全局变量
HINSTANCE g_hInst;
const int KeyPressMask=0x80000000; //键盘掩码常量
char g_PrvChar;
//声明共享区
#pragma data_seg("shared")
static HHOOK g_hHook=NULL;
static int m_abc=3;
static CPoint m_point=NULL;
#pragma data_seg()
一个简单的关于鼠标移动的消息钩子代码 全局消息钩子是病毒吗
#pragma comment(linker, "/SECTION:shared,rws")
//声明回调函数
LRESULT CALLBACK MouseProc(int iCode,WPARAM wParam,LPARAMlParam);
static AFX_EXTENSION_MODULE MFCDllDLL = { NULL, NULL };

extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOIDlpReserved)
{
// Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved);

if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("MFCDLL.DLLInitializing!n");
g_hInst=hInstance;
// Extension DLL one-timeinitialization
if(!AfxInitExtensionModule(MFCDllDLL, hInstance))
return 0;

// Insert this DLL into theresource chain
// NOTE: If this Extension DLLis being implicitly linked to by
// an MFCRegular DLL (such as an ActiveX Control)
// instead ofan MFC application, then you will want to
// removethis line from DllMain and put it in a separate
// functionexported from this Extension DLL. The RegularDLL
// that usesthis Extension DLL should then explicitly call that
// functionto initialize this Extension DLL.Otherwise,
// theCDynLinkLibrary object will not be attached to the
// RegularDLL's resource chain, and serious problems will
//result.

newCDynLinkLibrary(MFCDllDLL);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
TRACE0("MFCDLL.DLLTerminating!n");
// Terminate the library beforedestructors are called
AfxTermExtensionModule(MFCDllDLL);
}
return 1; //ok
}

//声明导出函数,装载钩子
DLLEXPORT int CALLBACK InstallHOOK()
{
g_hHook=SetWindowsHookEx(WH_MOUSE,MouseProc,g_hInst,0);
if(g_hHook)
{
return TRUE;
}
else
{
return FALSE;
}

}
//卸载钩子
DLLEXPORT int CALLBACK UninstallHOOK()
{
if(UnhookWindowsHookEx(g_hHook)==0)
{
returnFALSE;
}
else
{
returnTRUE;
}

}

//定义回调函数
LRESULT CALLBACK MouseProc(int iCode,WPARAM wParam,LPARAMlParam)
{


//AfxMessageBox("鼠标正在移动");
//获取鼠标的位置,并且写入文件中
m_point.x=10;
m_point.y=10;
//获取当前的鼠标位置
GetCursorPos(&m_point);
FILE* file;
file=fopen("c:\bbaa.log","w+");
fprintf(file,"%d,%dn",m_point.x,m_point.y);
//获取IE浏览器的所在位置
HWNDhwnd=::FindWindow("IEFrame",NULL);
CRectm_rect;
::GetWindowRect(hwnd,m_rect);
CString m_temp;
m_temp.Format("IE位置 x=%d x1=%d y=%d y1=%d 鼠标位置[%d,%d]",m_rect.left,m_rect.right,m_rect.top,m_rect.bottom,m_point.x,m_point.y);
fprintf(file,m_temp);
fclose(file);
returnCallNextHookEx(g_hHook,iCode,wParam,lParam);

}
//获取当前的坐标位置

DLLEXPORT int CALLBACK GetPos()
{
return m_point.x;
}

MFCDll.def

; MFCDll.def : Declares the module parameters for the DLL.

LIBRARY"MFCDll"
DESCRIPTION 'MFCDll Windows Dynamic LinkLibrary'

EXPORTS
InstallHOOK
UninstallHOOK
GetPos

主应用代码

typedef int (CALLBACK*InstHOOK)();//写到CPP文件头部分

void CMyHookDlg::OnStartHook()
{
AfxMessageBox("正在装载全局钩子...");
// TODO: Add your control notification handlercode here
staticHINSTANCE hinstDLL;
staticInstHOOK insthook;
hinstDLL =LoadLibrary((LPCTSTR)"D:\VCProject\MFCDll\Release\MFCDll.dll");
AfxMessageBox("装载DLL完成...");
insthook=(InstHOOK)GetProcAddress(hinstDLL,"InstallHOOK");
insthook();
}

止此钩子代码完毕.

  

爱华网本文地址 » http://www.aihuau.com/a/25101016/322765.html

更多阅读

一个简单的PS修片方法 ps简单方法换成白背景

以前看人家照片照的好,总问,PS了吗?被问的人总是不大高兴,认为污辱了自己的摄影水平其实水平再高的人,尤其是给孩子拍照,也不可能保证每张都是佳片,很多时候看宝贝儿表情很好,拿起相机一照,相机里没设置好,出的片子效果不满意,等调好了再拍,又

君子远庖厨的真正含义 君子远庖厨是伪善吗

君子之于禽兽也,见其生,不忍见其死;闻其声,不忍食其肉。是以君子远庖厨也。这是今天早晨在地铁时,翻看四书五经中,《论语》中的记载,断章取义果然是要不得啊!如果不看前半部分,那么君子远庖厨似乎仅仅是作为一个衣冠楚楚的公子,不应该受烟熏

一个简单的方法——防止电脑感染病毒图 防止手术感染的方法

这篇文章是我自己经验的总结,放在这里,也许可以帮助对电脑不熟悉的网友,减少甚至避免今后在网络上受到病毒袭击。如果文中有错误或者值得改进之处,欢迎各位提出——xyh一个简单的方法——防止电脑感染病毒我们常常遇到这样的问题,就是新

声明:《一个简单的关于鼠标移动的消息钩子代码 全局消息钩子是病毒吗》为网友恰似一种蜕变分享!如侵犯到您的合法权益请联系我们删除