//************************************************** ************************************************** ************

void longo(){//MessageBox(NULL, "Longo", "Cubo", 0);


++CUBI;

GetCursorPos(&coord); //al primo colpo 20%
SetCursorPos(coord.x = x , coord.y = y );
mouse_event(MOUSEEVENTF_LEFTDOWN,0 , 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); //MessageBox(NULL, "Dovrei averlo preso...", "Cubo", 0);
Sleep(2000);
nuovoC=0;
if (nuovoC==0&&UnaCliccata==0){UnaCliccata=1; nuovoF(); nuovoC=1;};
if (nuovoC==1){UnaCliccata=0; mouse(); };




cicloF = 0;

} //fine della funzione longo()


//************************************************** *************************************


void ControllaSchermo1()
{ // MessageBox(NULL, "Controlla schermo", "Cubo", 0);
// Rappresenta un pixel in una DIB a 24 bpp
struct DIB24BPPPixel
{
BYTE Blue;
BYTE Green;
BYTE Red;
};
// I device context
HDC dibDC=NULL, screenDC=NULL;
// Larghezza e altezza dello schermo (e di conseguenza della DIB)
LONG width, height;
// Bitmap selezionata all'inizio in dibDC, DIB Section
HBITMAP oldBmp=NULL, dibSection=NULL;
// Puntatore ai dati della DIB
LPBYTE dibBits=NULL;
// Struttura utilizzata per inizializzare la DIB
BITMAPINFO bi={0};
try
{
// I device context
HDC dibDC=NULL, screenDC=NULL;
// Larghezza e altezza dello schermo (e di conseguenza della DIB)
LONG width, height;
// Bitmap selezionata all'inizio in dibDC, DIB Section
HBITMAP oldBmp=NULL, dibSection=NULL;
// Puntatore ai dati della DIB
LPBYTE dibBits=NULL;
// Struttura utilizzata per inizializzare la DIB
BITMAPINFO bi={0};
// Lunghezza di una riga della DIB in byte; ci torna utile averlo pronto visto che le righe devono essere allineate a 32 bit
size_t bytesPerLine=0;
// Ottiene le dimensioni dello schermo
width = (LONG) GetSystemMetrics(SM_CXFULLSCREEN);
height = (LONG) GetSystemMetrics(SM_CYFULLSCREEN);
// Calcola la lunghezza di una riga della DIB
bytesPerLine = ((width * 24 + 31) & (~31)) / 8;
// Ottiene l'handle al DC dello schermo
screenDC = GetDC(0);
if(screenDC == NULL)
throw std::runtime_error("Impossibile ottenere il DC dello schermo; GetDC ha restituito NULL.");
// Inizializza i dati della DIB
bi.bmiHeader.biSize=sizeof(bi.bmiHeader);
bi.bmiHeader.biWidth=width;
bi.bmiHeader.biHeight=height;
bi.bmiHeader.biPlanes=1;
bi.bmiHeader.biBitCount=24; /* per semplicità usiamo una DIB a 24 bpp qualunque sia la profondità di colore dello schermo */
bi.bmiHeader.biCompression=BI_RGB;
// Crea la DIB section
dibSection=CreateDIBSection(NULL, &bi, DIB_RGB_COLORS, (LPVOID *)&dibBits, NULL, 0);
if(dibSection == NULL)
throw std::runtime_error("Impossibile creare la DibSection; CreateDIBSection ha restituito NULL.");
// Crea il DC
dibDC = CreateCompatibleDC(NULL);
if(dibDC == NULL)
throw std::runtime_error("Impossibile creare il device context; CreateCompatibleDC ha restituito NULL.");
// Seleziona la DIB section nel DC e salva la bitmap di default attualmente contenuta nel DC
oldBmp == SelectObject(dibDC, dibSection);
for(int d=0;d<1;d++)
{ //MessageBox(NULL, "CICLO PIXEL", "Pixel", MB_ICONINFORMATION);
// Ciclo da ripetere per ogni controllo dello schermo
// Copia il contenuto dello schermo nella DIB section
BitBlt(dibDC, 0,0, width, height, screenDC, 0, 0, SRCCOPY);
// Qui controlla i pixel della DIB

{
for(y = 55; y</*height*/ 588 && cicloF==0; y++)
{
// Ottiene un puntatore al primo pixel della riga
DIB24BPPPixel * rowPtr = (DIB24BPPPixel *) (dibBits+(height-1-y)*bytesPerLine);
for(x=227; x</*width*/1030 && cicloF==0; x++)
{
// Verifica il colore del pixel
// Esempio:
if(
(rowPtr[x].Red==243 && rowPtr[x].Green==196 && rowPtr[x].Blue==137) || (rowPtr[x].Red==255 && rowPtr[x].Green==168 && rowPtr[x].Blue==136)||
(rowPtr[x].Red==255 && rowPtr[x].Green==179 && rowPtr[x].Blue==248) || (rowPtr[x].Red==166 && rowPtr[x].Green==119 && rowPtr[x].Blue==133)||
(rowPtr[x].Red==253 && rowPtr[x].Green==146 && rowPtr[x].Blue==85) || (rowPtr[x].Red==247 && rowPtr[x].Green==147 && rowPtr[x].Blue==90)||
(rowPtr[x].Red==245 && rowPtr[x].Green==145 && rowPtr[x].Blue==88) || (rowPtr[x].Red==231 && rowPtr[x].Green==146 && rowPtr[x].Blue==95)||
(rowPtr[x].Red==220 && rowPtr[x].Green==135 && rowPtr[x].Blue==84) // && (rowPtr[x].Red==238 && rowPtr[x+5].Green==172 && rowPtr[x+5].Blue==119)


)
{
// MessageBox(NULL, "Ciclo 1", "Ciclo", 0);


{HDC hdcScreen = GetDC(0);
COLORREF BESTIO = GetPixel(hdcScreen, 1039, 701);
ReleaseDC(0, hdcScreen);

BYTE RED_BESTIO, GREEN_BESTIO, BLUE_BESTIO;

RED_BESTIO = GetRValue(BESTIO);
GREEN_BESTIO = GetGValue(BESTIO);
BLUE_BESTIO = GetBValue(BESTIO);
int SOMMA_BESTII = (int)RED_BESTIO + (int)GREEN_BESTIO + (int)BLUE_BESTIO;


if (SOMMA_BESTII!=720) A1=1;
}//blocco del getpixel

longo(); // MessageBox(NULL, "Il pixel è rosso", "Pixel", MB_ICONINFORMATION);
}
}
}//fine for

}//fine for
}; //fine else
// Cleanup
ReleaseDC(NULL, screenDC);
SelectObject(dibDC, oldBmp);
DeleteDC(dibDC);
DeleteObject(dibSection);
}
catch(...)
{
// Cleanup in caso di errore
if( screenDC != NULL)
ReleaseDC(NULL, screenDC);
if(dibDC != NULL)
{
SelectObject(dibDC, oldBmp);
DeleteDC(dibDC);
}
if(dibSection != NULL)
DeleteObject(dibSection);
// Propaga l'eccezione
throw;
}
}