【转】再谈QQ自动登录(上)
3年前曾经用C++写过一个QQ自动登录器,作为一个程序员新手的入门之作,其技术含量那是相当的低。最近回过头看了一遍以前的代码,心潮澎湃,于是按捺不住用流行的C#重新写了一遍,用意在于对比软件开发的趋势。
c++版思路:
(1)启动QQ主程序
WinExec(strLoc,SW_HIDE); // strLoc为QQ程序地址
(2)找到登录窗口
pWnd = FindWindow(_T("#32770"), _T("QQ用户登录"));
(3) 找到QQ号码输入窗口并输入号码 (利用剪切板复制粘贴QQ号码)
c++版思路:
(1)启动QQ主程序
WinExec(strLoc,SW_HIDE); // strLoc为QQ程序地址
(2)找到登录窗口
pWnd = FindWindow(_T("#32770"), _T("QQ用户登录"));
(3) 找到QQ号码输入窗口并输入号码 (利用剪切板复制粘贴QQ号码)
1CComboBox *pCob = (CComboBox *)pWnd->GetDlgItem(138);
2 if (pCob)
3 {
4 //CString source;
5 if(OpenClipboard())
6 {
7 HGLOBAL clipbuffer;
8 char *buffer;
9 EmptyClipboard();
10 clipbuffer=GlobalAlloc(GMEM_DDESHARE,m_strCode.GetLength()+1);
11 buffer=(char *)GlobalLock(clipbuffer);
12 strcpy(buffer,LPCSTR(m_strCode));
13 GlobalUnlock(clipbuffer);
14 SetClipboardData(CF_TEXT,clipbuffer);
15 CloseClipboard();
16 }
17 pCob->SetCurSel(0);
18 pCob->DeleteString(0);
19 pCob->SendMessage(WM_PASTE, 0, 0);
20}
(4)输入QQ密码(因为密码输入框不支持粘贴,模拟键盘输入密码)2 if (pCob)
3 {
4 //CString source;
5 if(OpenClipboard())
6 {
7 HGLOBAL clipbuffer;
8 char *buffer;
9 EmptyClipboard();
10 clipbuffer=GlobalAlloc(GMEM_DDESHARE,m_strCode.GetLength()+1);
11 buffer=(char *)GlobalLock(clipbuffer);
12 strcpy(buffer,LPCSTR(m_strCode));
13 GlobalUnlock(clipbuffer);
14 SetClipboardData(CF_TEXT,clipbuffer);
15 CloseClipboard();
16 }
17 pCob->SetCurSel(0);
18 pCob->DeleteString(0);
19 pCob->SendMessage(WM_PASTE, 0, 0);
20}
1 pCob = (CComboBox *)pWnd->GetDlgItem(0x3e95);
2 if (pCob)
3 {
4 if (pCob->GetCurSel()==CB_ERR)
5 {
6 pCob->SetCurSel(0);
7 }
8 }
9
10 CWnd *pCwnd = pWnd->GetNextWindow(GW_CHILD);
11 pCwnd = pCwnd->GetNextWindow(GW_HWNDNEXT);
12 while (pCwnd != NULL)
13 {
14 if (pCwnd)//找到
15 {
16 CEdit *pPwd = (CEdit *)pCwnd->GetDlgItem(16038);
17 if (pPwd)
18 {
19 char buf[20];
20 memset(buf, 0, sizeof(buf));
21 int iRet = m_strPassword.GetLength();
22 pPwd->SetSel(0, -1);
23 pPwd->Clear();
24
25 i = 0;
26 while (i < iRet)
27 {
28 pPwd->SendMessage(WM_CHAR, (WPARAM)m_strPassword.GetAt(i), 0);
29 i++;
30 }
31 break;
32 }
33 }
34 pCwnd = pCwnd->GetNextWindow(GW_HWNDNEXT);
35 }
(5)模拟按下登录按钮2 if (pCob)
3 {
4 if (pCob->GetCurSel()==CB_ERR)
5 {
6 pCob->SetCurSel(0);
7 }
8 }
9
10 CWnd *pCwnd = pWnd->GetNextWindow(GW_CHILD);
11 pCwnd = pCwnd->GetNextWindow(GW_HWNDNEXT);
12 while (pCwnd != NULL)
13 {
14 if (pCwnd)//找到
15 {
16 CEdit *pPwd = (CEdit *)pCwnd->GetDlgItem(16038);
17 if (pPwd)
18 {
19 char buf[20];
20 memset(buf, 0, sizeof(buf));
21 int iRet = m_strPassword.GetLength();
22 pPwd->SetSel(0, -1);
23 pPwd->Clear();
24
25 i = 0;
26 while (i < iRet)
27 {
28 pPwd->SendMessage(WM_CHAR, (WPARAM)m_strPassword.GetAt(i), 0);
29 i++;
30 }
31 break;
32 }
33 }
34 pCwnd = pCwnd->GetNextWindow(GW_HWNDNEXT);
35 }
1 CButton *pbtn = (CButton *)pWnd->GetDlgItem(324);
2 if (pbtn)
3 {
4 if (QQInfo.type!=pbtn->GetCheck())
5 {
6 pbtn->PostMessage(WM_LBUTTONDOWN, 0, 0);
7 pbtn->PostMessage(WM_LBUTTONUP, 0, 0);
8 }
9 }
10
11 CButton *pbtnLogin = (CButton *)pWnd->GetDlgItem(16032);
12 if (pbtnLogin)
13 {
14 pbtnLogin->PostMessage(WM_LBUTTONDOWN, 0, 0);
15 pbtnLogin->PostMessage(WM_LBUTTONUP, 0, 0);
16 }
以上代码大量用到了消息处理,用程序完全模拟了我们登录QQ的过程2 if (pbtn)
3 {
4 if (QQInfo.type!=pbtn->GetCheck())
5 {
6 pbtn->PostMessage(WM_LBUTTONDOWN, 0, 0);
7 pbtn->PostMessage(WM_LBUTTONUP, 0, 0);
8 }
9 }
10
11 CButton *pbtnLogin = (CButton *)pWnd->GetDlgItem(16032);
12 if (pbtnLogin)
13 {
14 pbtnLogin->PostMessage(WM_LBUTTONDOWN, 0, 0);
15 pbtnLogin->PostMessage(WM_LBUTTONUP, 0, 0);
16 }