//包含DLL函数导出的头文件 #include "MSNHook.h"
//隐式导入
#pragma comment(lib,"MSNHook.lib")
//声明导入函数
__declspec(dllimport) BOOL WINAPI SetMsnHook(DWORD dwThreadId); __declspec(dllimport) void WINAPI GetText(int &x,int &y,char ** ptext); __declspec(dllimport) HWND WINAPI GetMyHwnd();//安装MSN钩子函数
void CTestMSNHookDlg::OnBnClickedOk() {
//通过SPY++可以看到MSN聊天对话框窗口类是IMWindowClass,通过这个得到该窗口句柄 CWnd *pMsnWin = FindWindow(TEXT("IMWindowClass"),NULL); if(pMsnWin == NULL) return ;
//通过窗口句柄得到对应的线程的ID SetMsnHook(GetWindowThreadProcessId(pMsnWin->GetSafeHwnd(),NULL)); MSG msg; GetMessage(&msg,NULL,0,0); SetTimer(101,100,NULL);
}
void CTestMSNHookDlg::OnTimer(UINT_PTR nIDEvent) {
//刷新消息 char * pText = NULL; int x = 0,y = 0; GetText(x,y,&pText); if(x ==0 && y ==0) return ; m_Edit.Format("%d:%d:%s",x,y,pText); //m_Edit = pText; UpdateData(FALSE);
HWND hWnd = GetMyHwnd(); CWnd * pWnd = CWnd::FromHandle(hWnd); pWnd->GetWindowText(m_Edit); CDialog::OnTimer(nIDEvent); }
void CTestMSNHookDlg::OnBnClickedButton1() {
//关闭 KillTimer(101); SetMsnHook(0); OnCancel(); } 好了,基本上就这些了。这里有个问题,我本想得到MSN用户聊天时输入的聊天信息,这里通过WM_GETTEXT消息的不到,如果有知道的朋友告诉一声。
|