效果图如下:
具体代码如下:

1 // WowlauDlg.cpp : implementation file 2 // 3 4 #include "stdafx.h" 5 #include "Wowlau.h" 6 #include "WowlauDlg.h" 7 #include <locale>//为了使用setlocale(LC_CTYPE, "chs");便于输入中文到txt中 8 #include <cstring> 9 #include "windows.h" 10 #include "winuser.h" 11 #include "Shlwapi.h" 12 #include <time.h> 13 #include <conio.h> 14 #include <stdio.h> 15 #include "XSleep.h" 16 17 #ifdef _DEBUG 18 #define new DEBUG_NEW 19 #define WM_SENDSTRING WM_USER+100 20 #undef THIS_FILE 21 static char THIS_FILE[] = __FILE__; 22 #endif 23 int x = 0; 24 DWORD WINAPI ClientThread(LPVOID lpParam){ 25 int i = 0; 26 while (i < 10){ 27 } 28 return 0; 29 } 30 void ShowCount1() 31 { 32 CString str; 33 int i = 0; 34 HWND hwnd = AfxGetApp()->GetMainWnd()->GetSafeHwnd(); 35 while(i < 10) 36 { 37 Sleep(20); 38 // str.Format(_T("已耗时%d秒,请稍候..."),i+1); 39 // ::SetWindowText(hwnd,str); 40 i ++; 41 } 42 43 } 44 void ShowCount2() 45 { 46 CString str; 47 int i = 0; 48 HWND hwnd = AfxGetApp()->GetMainWnd()->GetSafeHwnd(); 49 while(i < 10) 50 { 51 Sleep(100); 52 // str.Format(_T("已耗时%d秒,请稍候..."),i+1); 53 // ::SetWindowText(hwnd,str); 54 i ++; 55 } 56 57 } 58 void ShowCount3() 59 { 60 CString str; 61 int i = 0; 62 HWND hwnd = AfxGetApp()->GetMainWnd()->GetSafeHwnd(); 63 while(i < 10) 64 { 65 Sleep(50); 66 // str.Format(_T("已耗时%d秒,请稍候..."),i+1); 67 // ::SetWindowText(hwnd,str); 68 i ++; 69 } 70 71 } 72 73 struct XSleep_Structure 74 { 75 int duration; 76 HANDLE eventHandle; 77 }; 78 79 80 DWORD WINAPI XSleepThread(LPVOID pWaitTime) 81 { 82 XSleep_Structure *sleep = (XSleep_Structure *)pWaitTime; 83 84 Sleep(sleep->duration); 85 SetEvent(sleep->eventHandle); 86 87 return 0; 88 } 89 90 void XSleep(int nWaitInMSecs) 91 { 92 XSleep_Structure sleep; 93 94 sleep.duration = nWaitInMSecs; 95 sleep.eventHandle = CreateEvent(NULL, TRUE, FALSE, NULL); 96 97 DWORD threadId; 98 CreateThread(NULL, 0, &XSleepThread, &sleep, 0, &threadId); 99 100 MSG msg; 101 102 while(::WaitForSingleObject(sleep.eventHandle, 0) == WAIT_TIMEOUT) 103 { 104 //get and dispatch messages 105 if(::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 106 { 107 ::TranslateMessage(&msg); 108 ::DispatchMessage(&msg); 109 } 110 } 111 112 CloseHandle(sleep.eventHandle); 113 } 114 115 //https://bbs.csdn.net/topics/300057427 116 struct SInfo 117 { 118 public: 119 SInfo() 120 { 121 strInfo = ""; 122 }; 123 CString strInfo; 124 }; 125 126 ///////////////////////////////////////////////////////////////////////////// 127 // CAboutDlg dialog used for App About 128 129 class CAboutDlg : public CDialog 130 { 131 public: 132 CAboutDlg(); 133 DWORD m_dwPos; 134 afx_msg void OnBnClickedOk(); 135 static void WINAPI ShowCount(); 136 137 138 // Dialog Data 139 //{{AFX_DATA(CAboutDlg) 140 enum { IDD = IDD_ABOUTBOX }; 141 //}}AFX_DATA 142 143 // ClassWizard generated virtual function overrides 144 //{{AFX_VIRTUAL(CAboutDlg) 145 protected: 146 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support 147 //}}AFX_VIRTUAL 148 149 // Implementation 150 protected: 151 //{{AFX_MSG(CAboutDlg) 152 //}}AFX_MSG 153 DECLARE_MESSAGE_MAP() 154 155 }; 156 157 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) 158 { 159 //{{AFX_DATA_INIT(CAboutDlg) 160 //}}AFX_DATA_INIT 161 } 162 163 void CAboutDlg::DoDataExchange(CDataExchange* pDX) 164 { 165 CDialog::DoDataExchange(pDX); 166 //{{AFX_DATA_MAP(CAboutDlg) 167 //}}AFX_DATA_MAP 168 } 169 170 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) 171 //{{AFX_MSG_MAP(CAboutDlg) 172 // No message handlers 173 //}}AFX_MSG_MAP 174 END_MESSAGE_MAP() 175 176 ///////////////////////////////////////////////////////////////////////////// 177 // CWowlauDlg dialog 178 179 CWowlauDlg::CWowlauDlg(CWnd* pParent /*=NULL*/) 180 : CDialog(CWowlauDlg::IDD, pParent) 181 { 182 //{{AFX_DATA_INIT(CWowlauDlg) 183 184 //}}AFX_DATA_INIT 185 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 186 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 187 m_dwPos = 0; 188 } 189 190 void CWowlauDlg::DoDataExchange(CDataExchange* pDX) 191 { 192 CDialog::DoDataExchange(pDX); 193 //{{AFX_DATA_MAP(CWowlauDlg) 194 DDX_Control(pDX, IDC_COMBO3, m_Combo); 195 //}}AFX_DATA_MAP 196 } 197 198 BEGIN_MESSAGE_MAP(CWowlauDlg, CDialog) 199 //{{AFX_MSG_MAP(CWowlauDlg) 200 ON_WM_SYSCOMMAND() 201 ON_WM_PAINT() 202 ON_WM_QUERYDRAGICON() 203 ON_BN_CLICKED(IDWRITE, OnWrite) 204 ON_BN_CLICKED(IDREAD, OnRead) 205 ON_BN_CLICKED(IDTEST, OnTest) 206 ON_BN_CLICKED(IDADD, OnAdd) 207 ON_BN_CLICKED(IDDEL, OnDel) 208 ON_BN_CLICKED(IDWRITE2, OnWrite2) 209 ON_BN_CLICKED(IDRUN, OnRun) 210 ON_BN_CLICKED(ID_wowmyfan, Onwowmyfan) 211 ON_BN_CLICKED(ID_189, On189) 212 ON_WM_TIMER() 213 // ON_BN_CLICKED(ID_AUTOLOGIN, OnAutologin) 214 //}}AFX_MSG_MAP 215 END_MESSAGE_MAP() 216 217 ///////////////////////////////////////////////////////////////////////////// 218 // CWowlauDlg message handlers 219 220 BOOL CWowlauDlg::OnInitDialog() 221 { 222 CDialog::OnInitDialog(); 223 224 // Add "About..." menu item to system menu. 225 226 // IDM_ABOUTBOX must be in the system command range. 227 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); 228 ASSERT(IDM_ABOUTBOX < 0xF000); 229 230 CMenu* pSysMenu = GetSystemMenu(FALSE); 231 if (pSysMenu != NULL) 232 { 233 CString strAboutMenu; 234 strAboutMenu.LoadString(IDS_ABOUTBOX); 235 if (!strAboutMenu.IsEmpty()) 236 { 237 pSysMenu->AppendMenu(MF_SEPARATOR); 238 pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); 239 } 240 } 241 242 // Set the icon for this dialog. The framework does this automatically 243 // when the application's main window is not a dialog 244 SetIcon(m_hIcon, TRUE); // Set big icon 245 SetIcon(m_hIcon, FALSE); // Set small icon 246 247 // TODO: Add extra initialization here 248 // GetDlgItem(IDC_COMBO2) -> SetWindowText("请选择"); 249 250 // m_COMBO1.AddString("StringData1"); 251 // ((CComboBox*)GetDlgItem(IDC_COMBO2)) -> AddString("COM1"); 252 // ((CComboBox*)GetDlgItem(IDC_COMBO2)) -> AddString("COM2"); 253 254 255 return TRUE; // return TRUE unless you set the focus to a control 256 } 257 258 void CWowlauDlg::OnSysCommand(UINT nID, LPARAM lParam) 259 { 260 if ((nID & 0xFFF0) == IDM_ABOUTBOX) 261 { 262 CAboutDlg dlgAbout; 263 dlgAbout.DoModal(); 264 } 265 else 266 { 267 CDialog::OnSysCommand(nID, lParam); 268 } 269 } 270 271 // If you add a minimize button to your dialog, you will need the code below 272 // to draw the icon. For MFC applications using the document/view model, 273 // this is automatically done for you by the framework. 274 275 void CWowlauDlg::OnPaint() 276 { 277 if (IsIconic()) 278 { 279 CPaintDC dc(this); // device context for painting 280 281 SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); 282 283 // Center icon in client rectangle 284 int cxIcon = GetSystemMetrics(SM_CXICON); 285 int cyIcon = GetSystemMetrics(SM_CYICON); 286 CRect rect; 287 GetClientRect(&rect); 288 int x = (rect.Width() - cxIcon + 1) / 2; 289 int y = (rect.Height() - cyIcon + 1) / 2; 290 291 // Draw the icon 292 dc.DrawIcon(x, y, m_hIcon); 293 } 294 else 295 { 296 CDialog::OnPaint(); 297 } 298 } 299 300 // The system calls this to obtain the cursor to display while the user drags 301 // the minimized window. 302 HCURSOR CWowlauDlg::OnQueryDragIcon() 303 { 304 return (HCURSOR) m_hIcon; 305 } 306 307 void CWowlauDlg::OnWrite() 308 { 309 // TODO: 在此添加控件通知处理程序代码 310 /*CString filename = _T("I:\\BaiduYunDownload\\wowold.net\\wowold.net\\realmlist.wtf");//在本例中路径为:E:\work\BruceXu\CodeRelevant\mytestcode\读写txt\ReadWriteTxt\ReadWriteTxt\Test.txt 311 CString strWriteData, str, str1 = "SET realmlist ", str2; 312 ((CEdit*)GetDlgItem(IDC_EDIT1)) -> GetWindowText(str2); 313 //((CEdit*)GetDlgItem(IDC_EDIT1)) -> SetWindowText("lalalala"); 314 315 CStdioFile myFile; 316 myFile.ReadString(str); 317 int nPos = str.Find(' '); 318 nPos = str.Find(' ', nPos+1); 319 CString strRight = str.Right(str.GetLength()-nPos-1); 320 321 strWriteData.Format(strRight); 322 CStdioFile csFile; 323 CFileException cfException; 324 if (csFile.Open(filename, CFile::typeText | CFile::modeCreate | CFile::modeReadWrite | CFile::modeNoTruncate, &cfException))//以txt方式读取|若没有文件则创建该文件|文件打开时不清除 325 { 326 csFile.SeekToEnd(); 327 setlocale(LC_CTYPE, "chs");//为了能用csFile.WriteString(strWriteData)写入中文 328 csFile.WriteString(strWriteData); 329 } 330 331 csFile.Close(); */ 332 char* pszFileName="I:\\BaiduYunDownload\\wowold.net\\wowold.net\\realmlist.wtf"; 333 CString strWriteData, str = "SET realmlist ", str1, str2; 334 CStdioFile myFile; 335 ((CEdit*)GetDlgItem(IDC_EDIT1)) -> GetWindowText(str1); 336 str2 = str + str1; 337 strWriteData.Format(str2); 338 CFileException fileException; 339 if(myFile.Open(pszFileName,CFile::typeText | CFile::modeCreate | CFile::modeReadWrite),&fileException) 340 { 341 myFile.SeekToEnd(); 342 setlocale(LC_CTYPE, "chs");//为了能用csFile.WriteString(strWriteData)写入中文 343 myFile.WriteString(strWriteData); 344 } 345 346 myFile.Close(); 347 } 348 /*{ 349 350 CString strFilter,fileName; 351 352 strFilter="Text Files(*.txt)|*.txt||"; 353 354 CFileDialog dlg(TRUE, NULL, NULL, OFN_EXPLORER|OFN_HIDEREADONLY|OFN_ENABLESIZING|OFN_FILEMUSTEXIST,strFilter); 355 356 if(dlg.DoModal() == IDOK )//显示打开文件对话框 357 358 { 359 360 fileName=dlg.GetPathName(); 361 362 CFile openfile(fileName,CFile::modeRead);//构造CFile对象 363 364 int length=openfile.GetLength();//获取文件长度 365 366 char *strText; 367 368 strText=new char[length]; 369 370 openfile.Read(strText,length); 371 372 openfile.Close();//关闭文件 373 374 m_strRead=(CString)strText; 375 376 delete [] strText; 377 378 UpdateData(false); 379 380 }8*/ 381 void CWowlauDlg::OnRead() 382 { 383 // TODO: Add your control notification handler code here 384 char* pszFileName="I:\\BaiduYunDownload\\wowold.net\\wowold.net\\realmlist.wtf"; 385 CString filename = _T("I:\\BaiduYunDownload\\wowold.net\\wowold.net\\realmlist.wtf");//在本例中路径为:E:\work\BruceXu\CodeRelevant\mytestcode\读写txt\ReadWriteTxt\ReadWriteTxt\Test.txt 386 CStdioFile myFile; 387 CString strWriteData, str2, MyStr; 388 strWriteData.Format(str2); 389 CFileException fileException; 390 if(myFile.Open(pszFileName,CFile::typeText|CFile::modeReadWrite),&fileException) 391 { 392 CString str2; 393 myFile.ReadString(str2); 394 //AfxMessageBox(str1+str2); 395 //SetDlgItemText(IDC_STATIC, str1 + str2); 396 SetDlgItemText(IDC_EDIT1, str2); // 这里str2的作用域只在这对大括号里,不能在大括号外 397 MyStr.Format(str2); // 格式字符串,并赋值给 MyStr,这样,str2的作用域就在这个::OnRead()整个片区,这样下面的 AfxMessageBox(MyStr); 就可以访问 读出的字符串了,不加这句,读出的是乱码 398 } 399 else 400 { 401 TRACE("Can't open file %s,error=%u\n",pszFileName,fileException.m_cause); 402 } 403 404 myFile.Close(); 405 406 } 407 408 void CWowlauDlg::OnTest() 409 { 410 // TODO: Add your control notification handler code here 411 CString str1, str2, m_str = "123456"; 412 ((CEdit*)GetDlgItem(IDC_EDIT1)) -> GetWindowText(str1); 413 ((CEdit*)GetDlgItem(IDC_EDIT1)) -> SetWindowText("SET realmlist ptr.darrowshire.com"); 414 ((CComboBox*)GetDlgItem(IDC_COMBO3))->GetWindowText(str2); 415 416 // AfxMessageBox(str2); 417 //能使用str==NULL来判断,NULL一般只拿和指针做比较或者赋给指针,string是类,传参进函数时str调用默认的构造函数已经初始化了,并且str都已经是对象了,它不可能为NULL,也不能和NULL比较。 418 if (TRUE == str2.IsEmpty()) // 判断字符串是否为空,不能用 str == NULL ,写法是错误的,可能会报空指针异常。可以用 str = "",或者sizeof(str2)==0或者 0 == str2.GetLength() 419 { 420 AfxMessageBox("请选择服务器..."); 421 } 422 else 423 AfxMessageBox(str2); 424 CWnd *pwnd = FindWindow(NULL, _T("魔兽世界")); 425 // CWnd *pwnd = FindWindow(_T("Notepad"),_T("无标题 - 记事本")); 426 HWND hwnd =pwnd->GetSafeHwnd(); //得到它的HWND 427 char str_id[] = "myfanwow"; 428 char str_psw[] = "123456"; 429 m_str = "123456"; 430 CString *msg = new CString("wowmyfan"); 431 CString cstr = _T("Helloo"); 432 433 // Sleep(5000); 434 435 // keybd_event('F',0,0,0); 436 // keybd_event('F',0,2,0); 437 if(hwnd) 438 { 439 // HWND hEdit = FindWindowEx(hwnd, NULL, "Edit", NULL); 440 // if(hEdit)//have found! 441 //use it !for example: 442 // ::PostMessage(hEdit, WM_SENDSTRING, (LPARAM)msg, 0); 443 for (int i =0; i < sizeof(str_id); i++) 444 { 445 ::SendMessage(hwnd, WM_CHAR, str_id[i], 0);;//发送‘A’到notepad 446 // ::SendMessage(hEdit, WM_SETTEXT, 0, (WPARAM)(LPCTSTR)cstr);//这个可用 447 // ::SendMessage(hEdit, WM_SETTEXT, 0, (WPARAM)(LPCTSTR)cstr);//这个可用 448 Sleep(500); 449 } 450 ::PostMessage(hwnd, WM_CHAR, 9, 0); 451 452 /* for (int j = 0; j < sizeof(str_psw); j ++) 453 { 454 ::PostMessage(hEdit, WM_CHAR, str_psw[j], 0); 455 Sleep(500); 456 }*/ 457 458 } 459 460 461 462 // ::SendMessage(hwnd, WM_CLOSE, 0, 0); //这个有效 463 464 465 466 } 467 468 469 470 void CWowlauDlg::OnAdd() 471 { 472 // TODO: Add your control notification handler code here 473 /* 474 TCHAR ws[256]; 475 CString temp, strTemp; 476 CComboBox* pcombo = ((CComboBox*)GetDlgItem(IDC_COMBO3)); 477 ((CComboBox*)GetDlgItem(IDC_COMBO3)) -> GetWindowText((LPTSTR)ws, 256);//可以不带 LPTSTR 478 // ((CComboBox*)GetDlgItem(IDC_COMBO3))->GetLBText(IDC_COMBO3, strTemp); 479 // pcombo->GetWindowText(strTemp); 480 int pos = pcombo -> GetCount(); 481 int flag; 482 char str[25]; 483 for (int i =0; i < pos; i ++) 484 { 485 pcombo->GetLBText(i, strTemp); 486 if ( ws == strTemp) 487 { 488 flag = 1; 489 break; 490 } 491 else 492 { 493 flag = 0; 494 } 495 } 496 497 char* pszFileName="I:\\BaiduYunDownload\\wowold.net\\wowold.net\\realmlist.wtf"; 498 if (flag == 0) 499 { 500 AfxMessageBox(ws); 501 pcombo->AddString(ws); 502 AfxMessageBox(itoa(flag, (LPSTR)(LPCTSTR)temp, 10)); 503 pos++; 504 UpdateData(TRUE); 505 } 506 else 507 { 508 AfxMessageBox("数据重复"); 509 } 510 */ 511 512 TCHAR ws[256]; 513 CString temp, strTemp, strWriteData, str = "SET realmlist ", str1, str2;; 514 515 CStdioFile myFile; 516 char* pszFileName="I:\\BaiduYunDownload\\wowold.net\\wowold.net\\realmlist.wtf"; 517 CComboBox* pcombo = ((CComboBox*)GetDlgItem(IDC_COMBO3)); 518 ((CComboBox*)GetDlgItem(IDC_COMBO3)) -> GetWindowText((LPTSTR)ws, 256);//可以不带 LPTSTR 519 // ((CComboBox*)GetDlgItem(IDC_COMBO3))->GetLBText(IDC_COMBO3, strTemp); 520 // pcombo->GetWindowText(strTemp); 521 int pos = pcombo -> GetCount(); 522 int flag; 523 // char str[25]; 524 for (int i =0; i < pos; i ++) 525 { 526 pcombo->GetLBText(i, strTemp); 527 if ( ws == strTemp) 528 { 529 flag = 1; 530 break; 531 } 532 else 533 { 534 flag = 0; 535 } 536 } 537 538 539 if (flag == 0) 540 { 541 AfxMessageBox(ws); 542 pcombo->AddString(ws); 543 AfxMessageBox(itoa(flag, (LPSTR)(LPCTSTR)temp, 10)); 544 pos++; 545 UpdateData(TRUE); 546 } 547 else 548 { 549 AfxMessageBox("数据重复"); 550 } 551 SetDlgItemText(IDC_STATIC, (itoa(pos, (LPSTR)(LPCTSTR)strTemp, 10))); 552 553 // AfxMessageBox(ws); 554 555 // ((CComboBox*)GetDlgItem(IDC_COMBO3)) -> AddString("login.ymwow.com"); 556 // AfxMessageBox(ws); 557 558 559 } 560 561 void CWowlauDlg::OnDel() 562 { 563 // TODO: Add your control notification handler code here 564 UpdateData(true); 565 TCHAR ws[256]; 566 567 CComboBox* pcombo = ((CComboBox*)GetDlgItem(IDC_COMBO3)); 568 int pos = pcombo -> GetCurSel(); 569 ((CComboBox*)GetDlgItem(IDC_COMBO3)) -> GetWindowText(ws, 256);//可以不带 LPTSTR 570 ((CComboBox*)GetDlgItem(IDC_COMBO3)) -> DeleteString(pos); 571 572 } 573 574 void CWowlauDlg::OnWrite2() 575 { 576 // TODO: Add your control notification handler code here 577 578 TCHAR ws[256]; 579 CString temp, strTemp, strWriteData, str = "SET realmlist ", str1, str2;; 580 581 CStdioFile myFile; 582 char* pszFileName="I:\\BaiduYunDownload\\wowold.net\\wowold.net\\realmlist.wtf"; 583 CComboBox* pcombo = ((CComboBox*)GetDlgItem(IDC_COMBO3)); 584 ((CComboBox*)GetDlgItem(IDC_COMBO3)) -> GetWindowText((LPTSTR)ws, 256);//可以不带 LPTSTR 585 // ((CComboBox*)GetDlgItem(IDC_COMBO3))->GetLBText(IDC_COMBO3, strTemp); 586 // pcombo->GetWindowText(strTemp); 587 int pos = pcombo -> GetCount(); 588 // int flag; 589 // char str[25]; 590 /* for (int i =0; i < pos; i ++) 591 { 592 pcombo->GetLBText(i, strTemp); 593 if ( ws == strTemp) 594 { 595 flag = 1; 596 break; 597 } 598 else 599 { 600 flag = 0; 601 } 602 } 603 604 605 if (flag == 0) 606 { 607 AfxMessageBox(ws); 608 pcombo->AddString(ws); 609 AfxMessageBox(itoa(flag, (LPSTR)(LPCTSTR)temp, 10)); 610 pos++; 611 UpdateData(TRUE);*/ 612 613 strWriteData.Format(ws); 614 CFileException fileException; 615 616 if(myFile.Open(pszFileName,CFile::typeText | CFile::modeCreate | CFile::modeReadWrite),&fileException) 617 { 618 myFile.SeekToEnd(); 619 setlocale(LC_CTYPE, "chs");//为了能用csFile.WriteString(strWriteData)写入中文 620 myFile.WriteString(str + strWriteData); 621 } 622 623 myFile.Close(); 624 /* } 625 else 626 { 627 AfxMessageBox("数据重复"); 628 } 629 */ 630 } 631 632 void CWowlauDlg::OnRun() 633 { 634 // TODO: Add your control notification handler code here 635 TCHAR ws[256]; 636 CString temp, strTemp, strWriteData, str = "SET realmlist ", str1, str2;; 637 638 CStdioFile myFile; 639 char* pszFileName="I:\\BaiduYunDownload\\wowold.net\\wowold.net\\realmlist.wtf"; 640 CComboBox* pcombo = ((CComboBox*)GetDlgItem(IDC_COMBO3)); 641 ((CComboBox*)GetDlgItem(IDC_COMBO3)) -> GetWindowText((LPTSTR)ws, 256);//可以不带 LPTSTR/*(1)取当前内容*/ 642 strTemp.Format(ws); 643 if ("" == strTemp) 644 { 645 AfxMessageBox("请选择服务器..."); 646 } 647 else 648 { 649 strWriteData.Format(ws); 650 CFileException fileException; 651 652 if((myFile.Open(pszFileName,CFile::typeText | CFile::modeCreate | CFile::modeReadWrite),&fileException) && ws != NULL) 653 { 654 myFile.SeekToEnd(); 655 setlocale(LC_CTYPE, "chs");//为了能用csFile.WriteString(strWriteData)写入中文 656 myFile.WriteString(str + strWriteData); 657 } 658 CWnd *pwnd = FindWindowA(NULL, _T("魔兽世界")); 659 // CWnd *pwnd = FindWindow(_T("Notepad"),NULL); 660 if (!pwnd) 661 { 662 PROCESS_INFORMATION lpProcessInformation; 663 STARTUPINFO startupinfo; 664 memset(&startupinfo,0,sizeof(STARTUPINFO)); 665 memset(&lpProcessInformation,0,sizeof(PROCESS_INFORMATION)); 666 startupinfo.cb = sizeof(STARTUPINFO); 667 startupinfo.dwFlags = STARTF_USESHOWWINDOW; 668 startupinfo.wShowWindow = SW_SHOWMAXIMIZED; 669 startupinfo.dwX = 100; 670 startupinfo.dwY = 100; 671 startupinfo.lpDesktop = NULL; 672 startupinfo.lpReserved = NULL; 673 startupinfo.lpReserved2 = NULL; 674 startupinfo.lpTitle = NULL; 675 // CreateProcess(_T("C:\\Windows\\System32\\notepad.exe"), NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &startupinfo, &lpProcessInformation); 676 CreateProcess(_T("I:\\BaiduYunDownload\\wowold.net\\wowold.net\\wow.exe"), NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &startupinfo, &lpProcessInformation); 677 } 678 679 myFile.Close(); 680 } 681 // ShellExecute(NULL, "open", "WoW.exe", NULL, "I:\\BaiduYunDownload\\wowold.net\\wowold.net", SW_SHOWMAXIMIZED); 682 // ShellExecute(NULL, "open", "I:\\BaiduYunDownload\\wowold.net\\wowold.net\\WoW.exe", NULL, NULL, SW_SHOWMAXIMIZED); 683 //打开指定exe程序,并传递命令行参数 684 /* SHELLEXECUTEINFO ShExecInfo; 685 ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); 686 ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS ; 687 ShExecInfo.hwnd = this -> m_hWnd; 688 ShExecInfo.lpVerb = _T("open"); 689 //输入要调用的exe文件路径 690 ShExecInfo.lpFile = _T("WoW.exe"); 691 //传入命令行参数数据 692 ShExecInfo.lpParameters = NULL; //若没有命令行参数,可为NULL */ 693 694 /*/------------------exe文件在当前路径下(可忽略)-------------- 695 //获取当前程序路径 696 TCHAR exeFullPath[200]; 697 GetModuleFileName(NULL,exeFullPath,100); 698 //获取程序运行当前路径 699 TCHAR drive[100],dir[100],fname[100],ext[20]; 700 _wsplitpath(exeFullPath,drive,dir,fname,ext); 701 CString dirPath; 702 dirPath.Format(_T("%s%s"),drive,dir); */ 703 //------------------------------------------------------------ 704 705 /* ShExecInfo.lpDirectory = "I:\\BaiduYunDownload\\wowold.net\\wowold.net";//这里exe的目录可忽略,写为NULL 706 ShExecInfo.nShow = SW_SHOWMAXIMIZED;//这里设置为显示exe界面,若设置为SW_SHOW,则可以显示exe界面 707 ShExecInfo.hInstApp = NULL; 708 CWowlauDlg::ShowWindow(SW_MINIMIZE);//点击运行后该窗口最小化到任何栏 709 //调用exe程序 710 ShellExecuteEx(&ShExecInfo); */ 711 //关闭该exe程序 712 /* if( ShExecInfo.hProcess != NULL) 713 { 714 //等待程序运行完毕 715 WaitForSingleObject(ShExecInfo.hProcess, INFINITE); 716 //关闭程序 717 TerminateProcess(ShExecInfo.hProcess,0); 718 ShExecInfo.hProcess = NULL; 719 } 720 */ 721 722 723 } 724 725 void CWowlauDlg::Onwowmyfan() 726 { 727 // TODO: Add your control notification handler code here 728 CWnd *pwnd = FindWindow(NULL, _T("魔兽世界")); 729 // CWnd *pwnd = FindWindow(_T("Notepad"),_T("无标题 - 记事本")); 730 HWND hwnd =pwnd->GetSafeHwnd(); //得到它的HWND 731 char str_id[] = "wowmyfan"; 732 char str_psw[] = "123456"; 733 CString *msg = new CString("wowmyfan"); 734 CString cstr = _T("Helloo"); 735 char str_id_h[] = "wowmyfan"; 736 char *p; 737 p = &str_id_h[0]; 738 char *p2 = new char[6]; 739 p2[6] = ('h', 's', 'o', 'f', 't', 'k'); 740 // Sleep(5000); 741 742 // keybd_event('F',0,0,0); 743 // keybd_event('F',0,2,0); 744 if(hwnd) 745 { 746 for (int i =0; i < sizeof(str_id_h); i++) 747 { 748 ::SendMessage(hwnd, WM_CHAR, p[i], 0);;//发送‘A’到notepad 749 // ::SendMessage(hEdit, WM_SETTEXT, 0, (WPARAM)(LPCTSTR)cstr);//这个可用 750 751 Sleep(250); 752 } 753 //按下TAB 754 ::PostMessage(hwnd, WM_KEYDOWN, VK_TAB, 0); 755 Sleep(250); 756 delete []p; 757 for (int j = 0; j < sizeof(str_psw); j ++) 758 { 759 ::PostMessage(hwnd, WM_CHAR, str_psw[j], 0); 760 Sleep(250); 761 } 762 } 763 ::PostMessage(hwnd, WM_KEYDOWN, VK_RETURN, 0); 764 } 765 766 void CWowlauDlg::On189() 767 { 768 // TODO: Add your control notification handler code here 769 int flag = 1, a = 0, o = 0, sum = 0, i = 1; 770 CString temp; 771 CWnd *pwnd = FindWindow(NULL, _T("魔兽世界")); 772 773 // CWnd *pwnd = FindWindow(_T("Notepad"),_T("无标题 - 记事本")); 774 HWND hwnd = pwnd->GetSafeHwnd(); //得到它的HWND 775 char str_id[] = "myfanwow"; 776 char str_psw[] = "123456"; 777 CString *msg = new CString("wowmyfan"); 778 CString cstr = _T("Helloo"); 779 // bool twnd = ::IsWindowVisible(hwnd); 780 781 782 /* keybd_event('F',0,0,0); 783 // keybd_event('F',0,2,0); 784 if(::IsWindowVisible(hwnd)) 785 { 786 for (int i =0; i < sizeof(str_id); i++) 787 { 788 ::SendMessage(hwnd, WM_CHAR, str_id[i], 0);;//发送‘A’到notepad 789 // ::SendMessage(hEdit, WM_SETTEXT, 0, (WPARAM)(LPCTSTR)cstr);//这个可用 790 fflush(stdout); 791 Sleep(250); 792 } 793 ::PostMessage(hwnd, WM_KEYDOWN, VK_TAB, 0); 794 Sleep(500); 795 796 for (int j = 0; j < sizeof(str_psw); j ++) 797 { 798 ::PostMessage(hwnd, WM_CHAR, str_psw[j], 0); 799 Sleep(250); 800 } 801 } 802 ::PostMessage(hwnd, WM_KEYDOWN, VK_RETURN, 0);*/ 803 804 805 // SetDlgItemText(IDC_STATIC, (itoa(sum, (LPSTR)(LPCTSTR)temp, 10))); 806 SetTimer(1, 1000, NULL); 807 // SetTimer(2, 1000, NULL); 808 809 } 810 811 /*/可用的 812 813 void CWowlauDlg::OnTimer(UINT nIDEvent) 814 { 815 // TODO: Add your message handler code here and/or call default 816 817 /* 这里一个简单的计时器代码 818 static int nTimer=0; 819 CString str=""; 820 str.Format("Timer: %d",nTimer++); 821 CWnd *pWnd=GetDlgItem(IDC_STATIC); //获取静态文本的指针 822 pWnd->SetWindowText(str); //在Lable中设置新值,表明定时器已经工作。 823 824 825 HANDLE g_event = CreateEvent(NULL,TRUE,FALSE,NULL); 826 CString MyStr; 827 char str_id[] = "myfanwow"; 828 char str_psw[] = "123456"; 829 CString *msg = new CString("wowmyfan"); 830 CString cstr = _T("Helloo"), my_str; 831 832 833 CWnd *pwnd = FindWindow(NULL, _T("魔兽世界")); 834 HWND hwnd = pwnd->GetSafeHwnd(); //得到它的HWND 835 int flag = 0; 836 if(::IsWindowVisible(hwnd)) 837 { 838 flag = 1; 839 MyStr.Format("%d 窗口启动成功", flag); 840 KillTimer(1); 841 } 842 else 843 { 844 flag = 0; 845 MyStr.Format("%d 窗口未启动,请稍候...", flag); 846 } 847 848 // SetDlgItemInt(IDC_STATIC, flag); 849 SetDlgItemText(IDC_STATIC, MyStr); 850 // DWORD id; 851 852 //SendMessage(hwnd, WM_CHAR, (WPARAM)&str,(LPARAM)0 ); 853 if(flag == 1) 854 { 855 for (int i =0; i < sizeof(str_id); i++) 856 { 857 ::SendMessage(hwnd, WM_CHAR, str_id[i], 0);;//发送‘A’到notepad 858 // ::SendMessage(hEdit, WM_SETTEXT, 0, (WPARAM)(LPCTSTR)cstr);//这个可用 859 // fflush(stdout); 860 XSleep(250); //用 XSleep(); 不会阻塞线程,其它,多线程、用定时器等,都会阻塞 861 // ShowCount3(); 862 // this -> EnableWindow(TRUE); 863 } 864 ::PostMessage(hwnd, WM_KEYDOWN, VK_TAB, 0); 865 866 ShowCount2(); 867 //HANDLE hTread = CreateThread(0,0,(LPTHREAD_START_ROUTINE)ShowCount1,0,0,&id); 868 //CloseHandle(hTread); 869 // WaitForSingleObject(g_event,1000);// 和上面的 HANDLE g_event = CreateEvent(NULL,TRUE,FALSE,NULL); 代码一起等同于 Sleep(1000); 870 871 for (int j = 0; j < sizeof(str_psw); j ++) 872 { 873 ::PostMessage(hwnd, WM_CHAR, str_psw[j], 0); 874 XSleep(250); 875 //ShowCount3(); 876 } 877 } 878 ::PostMessage(hwnd, WM_KEYDOWN, VK_RETURN, 0); 879 880 CDialog::OnTimer(nIDEvent); 881 }*/ 882 ///////////////////////////////////////// 883 884 void CWowlauDlg::OnTimer(UINT nIDEvent) 885 { 886 // TODO: Add your message handler code here and/or call default 887 CWnd *pwnd = FindWindow(NULL, _T("魔兽世界")); 888 HWND hwnd = pwnd->GetSafeHwnd(); //得到它的HWND 889 int flag = 0; 890 CString MyStr; 891 char str_id1[] = "wowmyfan", str_id2[] ="myfanwow" , str_id3[] = "mywowfan", str_psw[] = "123456"; 892 893 SInfo* info = new SInfo(); 894 info->strInfo = "wowmyfan"; 895 896 if(::IsWindowVisible(hwnd)) 897 { 898 flag = 1; 899 MyStr.Format("%d 窗口启动成功", flag); 900 KillTimer(1); 901 } 902 else 903 { 904 flag = 0; 905 MyStr.Format("%d 窗口未启动,请稍候...", flag); 906 } 907 908 char* pszFileName="I:\\BaiduYunDownload\\wowold.net\\wowold.net\\realmlist.wtf"; 909 CString filename = _T("I:\\BaiduYunDownload\\wowold.net\\wowold.net\\realmlist.wtf");//在本例中路径为:E:\work\BruceXu\CodeRelevant\mytestcode\读写txt\ReadWriteTxt\ReadWriteTxt\Test.txt 910 CStdioFile myFile; 911 CString strWriteData, str2, WtfStr; 912 strWriteData.Format(str2); 913 CFileException fileException; 914 if(myFile.Open(pszFileName,CFile::typeText|CFile::modeReadWrite),&fileException) 915 { 916 CString str2; 917 myFile.ReadString(str2); 918 //AfxMessageBox(str1+str2); 919 //SetDlgItemText(IDC_STATIC, str1 + str2); 920 SetDlgItemText(IDC_EDIT1, str2); // 这里str2的作用域只在这对大括号里,不能在大括号外 921 WtfStr.Format(str2); // 格式字符串,并赋值给 MyStr,这样,str2的作用域就在这个::OnRead()整个片区,这样下面的 AfxMessageBox(MyStr); 就可以访问 读出的字符串了,不加这句,读出的是乱码 922 } 923 else 924 { 925 TRACE("Can't open file %s,error=%u\n",pszFileName,fileException.m_cause); 926 } 927 myFile.Close(); 928 if (flag == 1) 929 { 930 if (strcmp(WtfStr, "SET realmlist login.ymwow.com") == 0) 931 { 932 for (int i = 0; i < sizeof(str_id1); i ++) 933 { 934 ::SendMessage(hwnd, WM_CHAR, str_id1[i], 0); 935 XSleep(250); //用 XSleep(); 不会阻塞线程,其它,多线程、用定时器等,都会阻塞 936 } 937 ::PostMessage(hwnd, WM_KEYDOWN, VK_TAB, 0); 938 ShowCount2(); 939 for (int j = 0; j < sizeof(str_psw); j ++) 940 { 941 ::PostMessage(hwnd, WM_CHAR, str_psw[j], 0); 942 XSleep(250); 943 } 944 } 945 else if (strcmp(WtfStr, "SET realmlist wow.newow.org") == 0) 946 { 947 for (int i = 0; i < sizeof(str_id2); i ++) 948 { 949 ::SendMessage(hwnd, WM_CHAR, str_id2[i], 0); 950 XSleep(250); //用 XSleep(); 不会阻塞线程,其它,多线程、用定时器等,都会阻塞 951 } 952 ::PostMessage(hwnd, WM_KEYDOWN, VK_TAB, 0); 953 ShowCount2(); 954 for (int j = 0; j < sizeof(str_psw); j ++) 955 { 956 ::PostMessage(hwnd, WM_CHAR, str_psw[j], 0); 957 XSleep(250); 958 } 959 } 960 else if (strstr(WtfStr, "1.14.76.54")!= NULL) 961 { 962 for (int i = 0; i < sizeof(str_id3); i ++) 963 { 964 ::SendMessage(hwnd, WM_CHAR, str_id3[i], 0); 965 XSleep(250); //用 XSleep(); 不会阻塞线程,其它,多线程、用定时器等,都会阻塞 966 } 967 ::PostMessage(hwnd, WM_KEYDOWN, VK_TAB, 0); 968 ShowCount2(); 969 for (int j = 0; j < sizeof(str_psw); j ++) 970 { 971 ::PostMessage(hwnd, WM_CHAR, str_psw[j], 0); 972 XSleep(250); 973 } 974 } 975 } 976 XSleep(250); 977 ::PostMessage(hwnd, WM_KEYDOWN, VK_RETURN, 0); 978 // AfxMessageBox(WtfStr); 979 SetDlgItemText(IDC_STATIC, MyStr); 980 CDialog::OnTimer(nIDEvent); 981 } 982 983 984 void CWowlauDlg::OnAutologin() 985 { 986 // TODO: Add your control notification handler code here 987 char* pszFileName="I:\\BaiduYunDownload\\wowold.net\\wowold.net\\realmlist.wtf"; 988 CString filename = _T("I:\\BaiduYunDownload\\wowold.net\\wowold.net\\realmlist.wtf");//在本例中路径为:E:\work\BruceXu\CodeRelevant\mytestcode\读写txt\ReadWriteTxt\ReadWriteTxt\Test.txt 989 CStdioFile myFile; 990 CString strWriteData, str2, MyStr; 991 992 strWriteData.Format(str2); 993 CFileException fileException; 994 if(myFile.Open(pszFileName,CFile::typeText|CFile::modeReadWrite),&fileException) 995 { 996 CString str2; 997 myFile.ReadString(str2); 998 SetDlgItemText(IDC_EDIT1, str2); 999 } 1000 else 1001 { 1002 TRACE("Can't open file %s,error=%u\n",pszFileName,fileException.m_cause); 1003 } 1004 myFile.Close(); 1005 1006 char str_id[] = "myfanwow"; 1007 char str_psw[] = "123456"; 1008 SInfo* msg = new SInfo(); 1009 msg -> strInfo = "wowmyfan"; 1010 char MyId[] = "wowmyfan"; 1011 CWnd *pwnd = FindWindow(NULL, _T("魔兽世界")); 1012 HWND hwnd = pwnd->GetSafeHwnd(); //得到它的HWND 1013 int flag = 0; 1014 if(::IsWindowVisible(hwnd)) 1015 { 1016 flag = 1; 1017 MyStr.Format("%d 窗口启动成功", flag); 1018 KillTimer(1); 1019 } 1020 else 1021 { 1022 flag = 0; 1023 MyStr.Format("%d 窗口未启动,请稍候...", flag); 1024 } 1025 1026 if (flag == 1) 1027 { 1028 if ("login.ymwow.com" == str2) 1029 { 1030 for (int i =0; i < sizeof(MyId); i++) 1031 { 1032 ::SendMessage(hwnd, WM_CHAR, MyId[i], 0);;//发送‘A’到notepad (LPARAM)&str 1033 XSleep(250); //用 XSleep(); 不会阻塞线程,其它,多线程、用定时器等,都会阻塞 1034 } 1035 ::PostMessage(hwnd, WM_KEYDOWN, VK_TAB, 0); 1036 ShowCount2(); 1037 1038 for (int j = 0; j < sizeof(str_psw); j ++) 1039 { 1040 ::PostMessage(hwnd, WM_CHAR, str_psw[j], 0); 1041 XSleep(250); 1042 } 1043 XSleep(250); 1044 ::PostMessage(hwnd, WM_KEYDOWN, VK_RETURN, 0); 1045 } 1046 if ("wow.newow.org" == str2) 1047 { 1048 for (int i =0; i < sizeof(str_id); i++) 1049 { 1050 ::SendMessage(hwnd, WM_CHAR, str_id[i], 0);;//发送‘A’到notepad (LPARAM)&str 1051 XSleep(250); //用 XSleep(); 不会阻塞线程,其它,多线程、用定时器等,都会阻塞 1052 } 1053 ::PostMessage(hwnd, WM_KEYDOWN, VK_TAB, 0); 1054 ShowCount2(); 1055 1056 for (int j = 0; j < sizeof(str_psw); j ++) 1057 { 1058 ::PostMessage(hwnd, WM_CHAR, str_psw[j], 0); 1059 XSleep(250); 1060 } 1061 XSleep(250); 1062 ::PostMessage(hwnd, WM_KEYDOWN, VK_RETURN, 0); 1063 } 1064 } 1065 }
左边的控件,是我先拿写个代码读出写入,本来我的意思是,直接修改SET realmlist 后面的代码,因为服务器IP前面是一样的,是SET realmlist,SET realmlist 后面字符串长度也不尽相等,而找了半天网上资料,没找到有替换文件里的部分字符串的写入方法,有的只是,读取文件里所有字符串,或者写入字符串到文件中。对文件读写就用到 myFile.Open(pszFileName,CFile::typeText | CFile::modeCreate | CFile::modeReadWrite),&fileException),基本上就是清空文件然后重新写入,可能由于我是个刚刚入门,哪位要是有前面替换文件里的基本段字符串的方法,望告之,不尽感谢。
然后左边实现读出写入 realmlist 文件后,就开始使用MFC 的组合框控件开始实现添加删除服务器IP,简单的实现添加或删除下拉列表功能还是比较简单的,在一个问题上花费了点时间,就是添加IP的时候判断现在列表中是否已经存在的时候,原代码为:
1 for (int i =0; i < pos; i ++) // 使用 for 循环判断列是否有重复 2 { 3 pcombo->GetLBText(i, strTemp); // 读取下拉框的数据保存到 strTemp 中 4 if ( ws == strTemp) // ws 是 需要添加的数据 判断 需要添加的数据是否和下拉框现有的数据相同, 5 { 6 break; // 数据相同,退出循环 7 } 8 else 9 { 10 continne; // 否则 继续对比数据 11 } 12 } 13 AfxMessageBox("数据重复"); 14 pcombo->AddString(ws);
结果可想而知,有无重复都会写入数据,于是我想是不是不能用 for 循环,改用 while 、do while,都是在判断条件的时候出了问题,就是网上找答案,搜索条件循环,终于找到有一条信息,在循环条件里设置一个 flag,于是再修改就得到正确的代码:
1 for (int i =0; i < pos; i ++) 2 { 3 pcombo->GetLBText(i, strTemp); 4 if ( ws == strTemp) 5 { 6 flag = 1; // 判断 如果有相同的数据,则 flag = 1, 7 break; 8 } 9 else 10 { 11 flag = 0; // 否则 flag = 0 12 } 13 } 14 15 // 然后在这里 判断 flag = 0, 即无重复数据时才写入数据 16 if (flag == 0) 17 { 18 AfxMessageBox(ws); 19 pcombo->AddString(ws); 20 AfxMessageBox(itoa(flag, (LPSTR)(LPCTSTR)temp, 10)); 21 pos++; // 这里每加一条,列表数就加1 22 UpdateData(TRUE); 23 } 24 else 25 { 26 AfxMessageBox("数据重复"); 27 } 28 SetDlgItemText(IDC_STATIC, (itoa(pos, (LPSTR)(LPCTSTR)strTemp, 10)));
添加,删除,写入,然后就是运行山口山可执行文件,运行了一段时间都没有问题。
可是每次运行后都是输入帐号和密码,有点烦,于是就想设置一个自动登陆按扭,就不用每次都输入帐号和密码了,说干就干,添加一个按扭,自动登陆,思路如下,先找到进程,然后找到输入帐号和密码的窗口ID,输入相应的帐号和密码回车OK。
想法就好,实现起来又发现了问题,山口山的登陆界面的帐号和密码框和界面同进程,同ID,这就不好办了,在网上找资料,找到有的人说山口山的界面是画上去,不是控件,于是用VC++的 spy来查找进程和 ID,发觉真是这么回事,这就不好办了,
想想另外办法,发现 山口山启动后输入提示符直接就在帐号输入框里了,有办法了,启动窗口后先写入帐号字符串,然后模拟键盘按下 TAB 键, 再输入密码字符串,再模拟键盘按下回车键,OK。于是就找向一个编辑框里输入字符串的方法,先用记事本试试, 有 SendMessage 方法可以实现,但实验好多方法,SendMessage方法向编辑框发送字符串,可以用WM_SENDSTRING,WM_SETTEXT这两个方法,,但怎么用都不能往记事本里发送字符串,倒是能够改写窗口的标题。看来是不能用 SendMessage 实现字符串的输入了,不过发现 SendMessage 的WM_CHAR方法可以输入字符,这样也行,大不了就用 for 循环来实现字符串输入。于是就有了下面两个按扭,每个按扭对应一个帐号。 运行了一两天没什么问题,也能够实现自动登陆了,虽然这个自动登陆缺陷很多,但我这个入门级的能凑合用也不错了;现在还有需要修改的地方,每次都要等山口山窗口出现后才能点自动登陆,这回要实现自动判断窗口是否出现,出现则输入帐号密码,否则就等待山口山窗口出现,于是开始用了 Sleep();来实现,不过问题又来了,
Sleep()老是会阻塞进程,这个真的很烦,有时候字符串输到一半卡住了,导致另一半不输入,又到网上找解决办法,有的说用线程,有的说用 Delay()来实现,说的线程暂时还不大理解,我把输入帐号和密码和SLEEP()代码放到头文件处,又发现 C++ 没有 Delay(), 这个命令,不过这都解决不了进程阻塞,还有用
1 void ShowCount1() 2 { 3 CString str; 4 int i = 0; 5 HWND hwnd = AfxGetApp()->GetMainWnd()->GetSafeHwnd(); 6 while(i < 10) 7 { 8 Sleep(20); 9 // str.Format(_T("已耗时%d秒,请稍候..."),i+1); 10 // ::SetWindowText(hwnd,str); 11 i ++; 12 }
来代替 Sleep(),不过都不能解决阻塞的问题,正当以为这个问题无法实现的时候,发现一大神自己写的,http://www.newxing.com/Code/VC/other/1460.html ,叫“C++ 非阻塞式延时函数XSleep”,用这个代替 Sleep()是完全解决阻塞的问题,完了用一个计时器来实时监控山口山窗口,再用XSleep()实现延时,基本上就实现在自动登陆了,效果图如下: