codice:
#include <string.h> #include <GL/glui.h> #include <GL/glut.h> #include <sstream> //Per stampare le variabili sui box #include <string> //Per stampare le variabili sui box #include <stdlib.h> //Random #include <time.h> #include <conio.h> #include <lua_prim.h> #include <string.h> #include <time.h> #include <windows.h> #include <stdio.h> #include <irrlicht.h> #include <stdexcept> using namespace std; void Longo(void); int x; int y; POINT coord; /* struct contenente le coordinate xy del mouse */ //**************************************************************************************************************** void longo(){//MessageBox(NULL, "Longo", "Cubo", 0); 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); } //fine della funzione longo() //*************************************************************************************** int end=1; int tasto=1; int main() { MessageBox(NULL, "Questo programma è un programma sperimentale a scopo didattico\nideato esclusivamente per lo studio dell DIB section con Dev-c++.\n\nPertanto:\n\nNON mi assumo alcuna responsabilità riguardo a scopi illeciti\nfacendo uso di questo programma.\n", "Il Rakka Kubetti", 0); Sleep(500); MessageBox(NULL, "Attivare risoluzine su windows 1280x800 altrimenti controllare le istruzioni e terminare immediatamente il programma", "Istruzioni", 0); Sleep(500); MessageBox(NULL, "Premere F1 per attivare il raccoglimento automatico dei kubetti\nPremere F2 per disattivare il raccoglimento automatico dei kubetti\nQuando si è premuto F2, premere F3 per terminare il programma\n\nAlcuni pc non dispongo di un processore abbastanza potente\nquindi se i tasti non funzionano tenerli premuti per 1-2 secondi", "Istruzioni", 0); for (;end==1;){ if(GetAsyncKeyState(VK_F3)< 0)end=0; if(GetAsyncKeyState(VK_F1)< 0)tasto=0; for (;tasto==0;){ if(GetAsyncKeyState(VK_F2)< 0)tasto=1; { // 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 ; y++) { // Ottiene un puntatore al primo pixel della riga DIB24BPPPixel * rowPtr = (DIB24BPPPixel *) (dibBits+(height-1-y)*bytesPerLine); for(x=227; x</*width*/1030 ; 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].Green==172 && rowPtr[x].Blue==119) ) { longo(); // MessageBox(NULL, "Il pixel è rosso", "Pixel", MB_ICONINFORMATION); } } }//fine for }//blocco }; //fine for // 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; }//fine catch } }//fine for finito }//fine for infinito MessageBox(NULL, "Programma terminato", "Il Rakka Kubetti", MB_ICONINFORMATION); }//fine int main