WEB开发网
开发学院软件开发VC VC实现的MSN Messager钩子程序 阅读

VC实现的MSN Messager钩子程序

 2007-03-18 21:28:08 来源:WEB开发网   
核心提示: DLL 的CPP文件#include "stdafx.h"#include "MSNHook.h"#include <stdio.h>// 下面几句的含义是告诉编译器将各变量放入它自己的数据共享节中#pragma data_seg(&qu

DLL 的CPP文件

#include "stdafx.h"
#include "MSNHook.h"
#include <stdio.h>
// 下面几句的含义是告诉编译器将各变量放入它自己的数据共享节中
#pragma data_seg("Shared")
HHOOK g_hhook = NULL;
DWORD g_dwThreadIdMsn = 0;
POINT MouseLoc={0,0};
char text[256]={0};
HWND g_Hwnd = NULL;
#pragma data_seg()
//告诉编译器设置共享节的访问方式为:读,写,共享
#pragma comment(linker,"/section:Shared,rws")
HINSTANCE g_hinstDll = NULL;
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
g_hinstDll = (HINSTANCE)hModule;
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
LRESULT WINAPI GetMsgProc(int nCode,WPARAM wParam, LPARAM lParam);
BOOL WINAPI SetMsnHook(DWORD dwThreadId)
{
OutputDebugString("SetMsnHook");
BOOL fOK = FALSE;
if(dwThreadId != 0)
{
OutputDebugString("SetMsnHook dwThreadId != 0");
g_dwThreadIdMsn = GetCurrentThreadId();
//安装WM_MOUSE钩子和处理函数GetMsgProc
g_hhook = SetWindowsHookEx(WH_MOUSE,GetMsgProc,g_hinstDll,dwThreadId);
fOK = (g_hhook != NULL);
if(fOK)
{
fOK = PostThreadMessage(dwThreadId,WM_NULL,0,0);
}
else
{
fOK = UnhookWindowsHookEx(g_hhook);
g_hhook = NULL;
}
}
return(fOK);
}
LRESULT WINAPI GetMsgProc(int nCode,WPARAM wParam, LPARAM lParam)
{
char temp[20];
sprintf(temp,"%d
",nCode);
OutputDebugString("temp");
if (nCode==HC_ACTION)
{
MOUSEHOOKSTRUCT *l=(MOUSEHOOKSTRUCT *)lParam;
MouseLoc=l->pt; //送鼠标位置
//char text[256] = "";
HWND hWnd = WindowFromPoint(l->pt);
if(hWnd)
{
//GetWindowText(hWnd,text,256);
SendMessage(hWnd,WM_GETTEXT,256,(LPARAM)(LPCTSTR)text);
// strcpy(text,"123455555");
  SendMessage(hWnd,WM_SETTEXT,256,(LPARAM)(LPCTSTR)text);
g_Hwnd = hWnd;
}
//SendMessage(WindowFromPoint(l->pt),WM_GETTEXT,256,(LPARAM)(LPCTSTR)psw);
}
return(CallNextHookEx(g_hhook,nCode,wParam,lParam));
}
void WINAPI GetText(int &x,int &y,char ** ptext)
{
x = MouseLoc.x;
y = MouseLoc.y;
*ptext = text;
}
HWND WINAPI GetMyHwnd()
{
return g_Hwnd;
}

Tags:VC 实现 MSN

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接