龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

VC实现的MSN Messager钩子程序(2)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
LRESULT WINAPI GetMsgProc(int nCode,WPARAM wParam, LPARAM lParam); BOOL WINAPI SetMsnHook(DWORD dwThreadId) { OutputDebugString("SetMsnHook"); BOOL fOK = FALSE; if(dwThreadId != 0) { OutputDebugString

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;
}

精彩图集

赞助商链接