1、
VC++代码:
1 #include <stdio.h> 2 #include <windows.h> 3 #include <wchar.h> 4 5 void MoveMouseZ(int _iX, int _iY); 6 HWND FindSubBtn01(HWND _hWndParent, char *pcSubWndText); 7 void PrintLocalTime(); 8 9 void main() 10 { 11 Sleep(1000 * 10); 12 PrintLocalTime(); 13 printf("\t 程序开始\n"); 14 15 char *pcParentWndText = "加速精灵 v2.6"; 16 char *pcSubBtnText = "连 接"; 17 18 bool bBtnConn = false; // 指示 "连 接"按钮 是否为可点击的状态 19 int iCounter = 0; 20 int iCounterMoveMouse = 0; 21 while (1) 22 { 23 iCounterMoveMouse ++; 24 if (iCounterMoveMouse >= 5) 25 { 26 //* 27 MoveMouseZ(0, 0); 28 MoveMouseZ(500, 300); 29 //*/ 30 31 iCounterMoveMouse = 0; 32 } 33 /* 34 HWND hWndParent = ::FindWindowA(NULL, pcParentWndText); 35 if (hWndParent == 0) 36 { 37 PrintLocalTime(); 38 printf("\t Window \"%s\" is not found .\n", pcParentWndText); 39 } 40 else 41 { 42 HWND hBtnLianJie = FindSubBtn01(hWndParent, pcSubBtnText); 43 if (hBtnLianJie == 0) 44 { 45 PrintLocalTime(); 46 printf("\t Sub Button \"%s\" is not found .\n", pcSubBtnText); 47 } 48 else 49 { 50 bool bEnabled = ::IsWindowEnabled(hBtnLianJie); 51 if (bEnabled) 52 { 53 PrintLocalTime(); 54 printf("\t 连接断开,即将尝试重新连接\n"); 55 56 bBtnConn = true; 57 iCounter = 0; 58 59 // 模拟 button click事件 60 // http://blog.sina.com.cn/s/blog_6414c87b0101892x.html 61 LONG idBtn = GetWindowLong(hBtnLianJie, GWL_ID); 62 ::SendMessageA(hWndParent, WM_COMMAND, MAKEWPARAM(idBtn, BN_CLICKED), (LPARAM)hBtnLianJie); 63 } 64 else 65 { 66 if (bBtnConn) 67 iCounter ++; 68 69 // 连续监测15次,"连 接"按钮都是不可点击的状态,则说明 貌似已经连上去了。 70 if (iCounter > 15) 71 { 72 PrintLocalTime(); 73 printf("\t 貌似 已经重新连接成功\n"); 74 75 bBtnConn = false; 76 iCounter = 0; 77 } 78 } 79 } 80 } 81 //*/ 82 ::Sleep(1000); 83 } 84 85 system("pause"); 86 } 87 88 // 找窗口"加速精灵 v2.6"下的,窗口标题为"连 接"的按钮 - 方式(1) 89 HWND FindSubBtn01(HWND _hWndParent, char *pcSubWndText) 90 { 91 HWND hWndLianJie = ::FindWindowExA(_hWndParent, NULL, "Button", pcSubWndText); 92 //printf("FindSubBtn01 : 0x%08X\n", hWndLianJie); 93 94 return hWndLianJie; 95 } 96 97 98 HWND g_hWndLianJie = 0; 99 100 BOOL CALLBACK EnumChildProc(HWND _hWndChild, LPARAM _lParam) 101 { 102 char bufText[512] = {0}; 103 ::GetWindowTextA(_hWndChild, bufText, sizeof(bufText)); 104 //printf("\t%s\n", bufText); 105 if (0 == strcmp((char*)_lParam, bufText)) 106 { 107 //printf("\t\t==\n"); 108 g_hWndLianJie = _hWndChild; 109 return false; 110 } 111 return true; 112 } 113 114 // 找窗口"加速精灵 v2.6"下的,窗口标题为"连 接"的按钮 - 方式(2) 115 HWND FindSubBtn02(HWND _hWndParent, char *pcSubWndText) 116 { 117 EnumChildWindows(_hWndParent, EnumChildProc, (LPARAM)pcSubWndText); 118 return g_hWndLianJie; 119 } 120 121 void MoveMouseZ(int _iX, int _iY) 122 { 123 // 新的 坐标点 (_iX, _iY) 124 125 // 屏幕分辨率 126 int iX = 1366; 127 int iY = 768; 128 // 乘数(为什么要乘以这个?暂时不知...) 129 int iZ = 65536; 130 //Sleep(2000); 131 ::mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, 0, 0, 0, 0); 132 //Sleep(1000); 133 ::mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, _iX * iZ / iX, _iY * iZ / iY, 0, 0); 134 } 135 136 void PrintLocalTime() 137 { 138 //获取当地的时间。 139 SYSTEMTIME stLocal; 140 ::GetLocalTime(&stLocal); 141 142 //显示时间的间隔。 143 printf("%04u%02u%02u %02u:%02u:%02u:%u \n", 144 stLocal.wYear, stLocal.wMonth, stLocal.wDay, 145 stLocal.wHour, stLocal.wMinute, stLocal.wSecond, 146 stLocal.wMilliseconds); 147 }
2、
时间: 2024-10-11 07:20:50