1、
VC++代码:
#include <stdio.h>
#include <windows.h>
#include <wchar.h> void MoveMouseZ(int _iX, int _iY);
HWND FindSubBtn01(HWND _hWndParent, char *pcSubWndText);
void PrintLocalTime(); void main()
{
Sleep( * );
PrintLocalTime();
printf("\t 程序开始\n"); char *pcParentWndText = "加速精灵 v2.6";
char *pcSubBtnText = "连 接"; bool bBtnConn = false; // 指示 "连 接"按钮 是否为可点击的状态
int iCounter = ;
int iCounterMoveMouse = ;
while ()
{
iCounterMoveMouse ++;
if (iCounterMoveMouse >= )
{
//*
MoveMouseZ(, );
MoveMouseZ(, );
//*/ iCounterMoveMouse = ;
}
/*
HWND hWndParent = ::FindWindowA(NULL, pcParentWndText);
if (hWndParent == 0)
{
PrintLocalTime();
printf("\t Window \"%s\" is not found .\n", pcParentWndText);
}
else
{
HWND hBtnLianJie = FindSubBtn01(hWndParent, pcSubBtnText);
if (hBtnLianJie == 0)
{
PrintLocalTime();
printf("\t Sub Button \"%s\" is not found .\n", pcSubBtnText);
}
else
{
bool bEnabled = ::IsWindowEnabled(hBtnLianJie);
if (bEnabled)
{
PrintLocalTime();
printf("\t 连接断开,即将尝试重新连接\n"); bBtnConn = true;
iCounter = 0; // 模拟 button click事件
// http://blog.sina.com.cn/s/blog_6414c87b0101892x.html
LONG idBtn = GetWindowLong(hBtnLianJie, GWL_ID);
::SendMessageA(hWndParent, WM_COMMAND, MAKEWPARAM(idBtn, BN_CLICKED), (LPARAM)hBtnLianJie);
}
else
{
if (bBtnConn)
iCounter ++; // 连续监测15次,"连 接"按钮都是不可点击的状态,则说明 貌似已经连上去了。
if (iCounter > 15)
{
PrintLocalTime();
printf("\t 貌似 已经重新连接成功\n"); bBtnConn = false;
iCounter = 0;
}
}
}
}
//*/
::Sleep();
} system("pause");
} // 找窗口"加速精灵 v2.6"下的,窗口标题为"连 接"的按钮 - 方式(1)
HWND FindSubBtn01(HWND _hWndParent, char *pcSubWndText)
{
HWND hWndLianJie = ::FindWindowExA(_hWndParent, NULL, "Button", pcSubWndText);
//printf("FindSubBtn01 : 0x%08X\n", hWndLianJie); return hWndLianJie;
} HWND g_hWndLianJie = ; BOOL CALLBACK EnumChildProc(HWND _hWndChild, LPARAM _lParam)
{
char bufText[] = {};
::GetWindowTextA(_hWndChild, bufText, sizeof(bufText));
//printf("\t%s\n", bufText);
if ( == strcmp((char*)_lParam, bufText))
{
//printf("\t\t==\n");
g_hWndLianJie = _hWndChild;
return false;
}
return true;
} // 找窗口"加速精灵 v2.6"下的,窗口标题为"连 接"的按钮 - 方式(2)
HWND FindSubBtn02(HWND _hWndParent, char *pcSubWndText)
{
EnumChildWindows(_hWndParent, EnumChildProc, (LPARAM)pcSubWndText);
return g_hWndLianJie;
} void MoveMouseZ(int _iX, int _iY)
{
// 新的 坐标点 (_iX, _iY) // 屏幕分辨率
int iX = ;
int iY = ;
// 乘数(为什么要乘以这个?暂时不知...)
int iZ = ;
//Sleep(2000);
::mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, , , , );
//Sleep(1000);
::mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, _iX * iZ / iX, _iY * iZ / iY, , );
} void PrintLocalTime()
{
//获取当地的时间。
SYSTEMTIME stLocal;
::GetLocalTime(&stLocal); //显示时间的间隔。
printf("%04u%02u%02u %02u:%02u:%02u:%u \n",
stLocal.wYear, stLocal.wMonth, stLocal.wDay,
stLocal.wHour, stLocal.wMinute, stLocal.wSecond,
stLocal.wMilliseconds);
}
2、