1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
#include <windows.h>
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;
int click(HWND hwnd, int x, int y);
char titlu[200]="";
double Cx=0.5588235294117647,
Cy=0.6549019607843137;
COLORREF c = RGB(142,200,255);
int pixel_test(HWND hwnd, int x, int y)
{
HDC hDC = GetDC(hwnd);
COLORREF cr =GetPixel(hDC, x, y);
if(cr != CLR_INVALID)
{
return(abs(GetRValue(cr)-GetRValue(c))<=5 &&
abs(GetGValue(cr)-GetGValue(c))<=5 &&
abs(GetBValue(cr)-GetBValue(c))<=5);
}
return 0;
}
HWND mese[9];
int i=0;
BOOL CALLBACK MyEnumProc( HWND hwnd, LPARAM lParam )
{
if(GetWindowText(hwnd,titlu,200) && strstr(titlu, "My specific window"))
{
mese[i]=hwnd;
i++;
}
return 1;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
DWORD dwThreadId = GetCurrentThreadId(); // Get the current thread id
HDESK hDesktop = GetThreadDesktop(dwThreadId); // Assign the desktop thread id to hDesktop
while(1)
{
i=0;
EnumDesktopWindows( hDesktop, MyEnumProc, 0 );
for(int t=0; t<15; t++)
{
for (int j=0; j < i ; j++)
{
if (IsWindow(mese[j]))
{
RECT client;
GetClientRect(mese[j],&client);
int width=client.right-client.left;
int height=client.bottom-client.top;
int xscalat=(int)(width * Cx);
int yscalat=(int)(height * Cy);
if (pixel_test(mese[j],xscalat,yscalat) )
click(mese[j], xscalat, yscalat);
}
}
Sleep(4000);
}
}
return 0;
}
int click(HWND hwnd, int x, int y)
{
PostMessage(hwnd,WM_LBUTTONDOWN,0, MAKELONG(x,y));
PostMessage(hwnd,WM_LBUTTONUP,0, MAKELONG(x,y));
return 1;
}
|