Problem mit RGBQUAD-Variable! Wert wird nicht richtig erkannt!
-
Hi@LL
Erstmal danke fürs lesen ;).
Da ich jetzt länger mal wieder pausiert habe was das Codamieren angeht
und ich mich jetzt fast einen Monat mit diesem Thema beschäfige hehe...
bin ich jetzt doch mal auf Hilfe angewiesen.
Die RGBQUAD Variable wird durch eine CreateDIBSelect()erstellt und läuft
normalerweise auch einbahnfrei. Seit dem ich die Grafik vorher noch erstelle
geht hier etwas nicht mehr und ich verstehe nicht warum. Die RGBQUAD gibt einen Wert aus den die RGB-Bereiche aber nicht lesen können.Hier der Code! EIN KLEINER HINWEIS WÄRE NICHT SCHLECHT!

RGBQUAD* memory; OpenClipboard(NULL); HBITMAP hBmp = (HBITMAP) GetClipboardData(CF_BITMAP); CloseClipboard(); if(hBmp==NULL) { MessageBox(NULL,"Error GetClipboardData(CF_BITMAP)",NULL,MB_OK); DeleteDC(screen); PostQuitMessage(0); return 0; } if ( NULL == hBmp ) return false; HDC dcmem = CreateCompatibleDC ( NULL ); if ( NULL == SelectObject ( dcmem, hBmp ) ) { MessageBox(NULL,"Error SelectObjekt(dcmem,hBmp)",NULL,MB_OK); DeleteDC(screen); PostQuitMessage(0); return 0; } BITMAP bmp; if(GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp)==0) { MessageBox(NULL,"Error GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp)",NULL,MB_OK); DeleteDC(screen); PostQuitMessage(0); return 0; } SelectObject(hDC, hBmp); SetStretchBltMode(hDC,HALFTONE); if(StretchBlt(hDC, 0,0, dx,dy,dcmem,0, 0, dx+dx-dx/2,dy+dy-dy/2,SRCCOPY)==0) { MessageBox(NULL,"Error StretchBlt(hDC, 0, 0, dx, dy, dcmem, 0, 0, dx+dx-dx/2,dy+dy-dy/2,SRCCOPY)",NULL,MB_OK); DeleteDC(screen); PostQuitMessage(0); return 0; } ////////////////////////////////////////////////////////////////////////// ////////////Bis hier läuft alles noch normal!!!!///////////////////// ///////////////////////////////////////////////////////////////// if(GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp)==0) { MessageBox(NULL,"Error GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp)",NULL,MB_OK); DeleteDC(screen); PostQuitMessage(0); return 0; } SelectObject(hDC, hBmp); ///////////////Pixel finden im Bild//////////////////// bitmap = CreateDIBSection(hDC, &info, DIB_RGB_COLORS, (void**)&memory, 0, 0); if (bitmap==0) { MessageBox(NULL,"Error CreateDIBSection(hDC, &info, DIB_RGB_COLORS, (void**)&memory, 0, 0)",NULL,MB_OK); DeleteDC(screen); PostQuitMessage(0); return 0; } HDC hdcMemory = CreateCompatibleDC(hDC); HGDIOBJ oldbitmap = SelectObject(hdcMemory, bitmap); // BitBlt(hdcMemory, 0, 0, dx, dy, hDC, 0, 0, SRCCOPY); ////////////////----------------------------////////////////////// int tbytes = dx * dy; int r,g,b; // biBitCount = 32; for (i=0; i<tbytes; i++) { RGBQUAD *p = &memory[i]; //Die Werte sind nicht Compatible r=p->rgbRed; //Keinen Wert g=p->rgbGreen; b=p->rgbBlue;!!!BITTE NICHT DIE STRECHBLT BEACHTEN DAS HAT MIT MEINEM HDMI AUSGANG ZU TUN!!!
Danke nochmal!

-
Bitte Link in meiner Signatur anklicken und dann aufmerksam Lesen.
Anschließend editieren und richtig machen.Danke nochmal!

-
Hatte ich übersehen!

-
Vielen Dank!
#include <windows.h> #include <stdio.h> #include <string.h> #include "res.h" #include <time.h> #include <ctime> //process the window messages LRESULT CALLBACK windowProc(HWND, UINT, WPARAM, LPARAM); //extract RGB values from COLORREF //////////////////////////////BETA CODER///////////////////////////////////////// //DIRECTX MODULE umgehen mit Windows! Für Einsteiger! //////////////////// ////////////BEI manchen DIRECTX Programmen brauchen an noch einen Hook für die Tasten/// //timer id unsigned int timer = 1; //interval in ms to get the color unsigned int interval = 1; int dx = GetSystemMetrics(SM_CXSCREEN); int dy = GetSystemMetrics(SM_CYSCREEN); int timex =0; //main function int multi; bool LoadBMPIntoDC ( HDC hDC) { multi=3/2; ///////////////Daten////////////////////////////// BITMAPINFO info = {0}; info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); info.bmiHeader.biWidth = dx; info.bmiHeader.biHeight = dy; info.bmiHeader.biPlanes = 1; info.bmiHeader.biBitCount = 32; int x=1, y=1, i; HBITMAP bitmap; RGBQUAD* memory; ///////////////////////////////////////////////////// ///////////////Bild in den Speicher laden aus Clipboard////////////// if ( ( NULL == hDC ) ) return false; ///We then use the windows function LoadImage to load the bitmap into a Bitmap Handle: OpenClipboard(NULL); HBITMAP hBmp = (HBITMAP) GetClipboardData(CF_BITMAP); CloseClipboard(); if(hBmp==NULL) { /*MessageBox(NULL,"Error GetClipboardData(CF_BITMAP)",NULL,MB_OK); DeleteDC(screen); PostQuitMessage(0); return 0;*/ } if ( NULL == hBmp ) return false; HDC dcmem = CreateCompatibleDC ( hDC ); if ( NULL == SelectObject ( dcmem, hBmp ) ) { /*MessageBox(NULL,"Error SelectObjekt(dcmem,hBmp)",NULL,MB_OK); DeleteDC(screen); PostQuitMessage(0); return 0;*/ } BITMAP bmp; if(GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp)==0) { /*MessageBox(NULL,"Error GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp)",NULL,MB_OK); DeleteDC(screen); PostQuitMessage(0); return 0;*/ } SelectObject(hDC, hBmp); SetStretchBltMode(hDC,HALFTONE); if(StretchBlt(hDC, 0, 0, dx, dy, dcmem, 0, 0, dx, dy, SRCCOPY)==0) { /*MessageBox(NULL,"Error StretchBlt(hDC, 0, 0, dx, dy, dcmem, 0, 0, dx+dx-dx/2,dy+dy-dy/2,SRCCOPY)",NULL,MB_OK); DeleteDC(screen); PostQuitMessage(0); return 0;*/ } HDC UeberHdc = CreateCompatibleDC ( hDC ); UeberHdc = hDC; DeleteDC ( dcmem ); // clear up the memory dc return true; } /////////////////////////////////////////////////////////////////////////////////// bool FindPixelred1(HDC hDC) { if(!GetAsyncKeyState(0x10)) { keybd_event(0x2c, 0, 0, 0); keybd_event(0x2c,0, KEYEVENTF_KEYUP,0); int x=1, y=1, i; int dx = GetSystemMetrics(SM_CXSCREEN); int dy = GetSystemMetrics(SM_CYSCREEN); BITMAPINFO info = {0}; info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); info.bmiHeader.biWidth = dx; info.bmiHeader.biHeight = dy; info.bmiHeader.biPlanes = 1; info.bmiHeader.biBitCount = 32; // 32:RGBQUAD; 24:RGBTRIPLE HBITMAP bitmap; RGBQUAD* memory; bitmap = CreateDIBSection(hDC, &info, DIB_RGB_COLORS, (void**)&memory, 0, 0); //if(!bitmap || !memory) return ReleaseDC(0, hdcDesktop); HDC hdcMemory = CreateCompatibleDC(hdcMemory); HGDIOBJ oldbitmap = SelectObject(hdcMemory, bitmap); BitBlt(hdcMemory, 0, 0, dx, dy, hDC, 0, 0, SRCCOPY); SelectObject(hdcMemory, oldbitmap); DeleteDC(hdcMemory); //ReleaseDC(0, hdcDesktop); später int red,green,blue,rx,gx,bx; int tbytes = dx * dy; // biBitCount = 32; for (i=0; i<tbytes; i++) { RGBQUAD *p = &memory[i]; if (RGB(p->rgbRed, p->rgbGreen, p->rgbBlue) == RGB(255,0,0))//Rot //Hier die gewünschte Farbe einstellen { y = i / dx; x = i % dx; y = dy - y - 1; // nur wenn info.bmiHeader.biHeight ist positiv SetCursorPos(x,y); break; } } Sleep(100); DeleteObject(bitmap); } return true; } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { //program and class name const char *progName = "COPY to CLIPBOARD find PIXEL"; //create window class WNDCLASS windowClass; //message function windowClass.lpfnWndProc = windowProc; //enable redrawing windowClass.style = CS_HREDRAW | CS_VREDRAW; //program instance windowClass.hInstance = hInstance; //standard cursor windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); //standard icon windowClass.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON)); //gray background windowClass.hbrBackground = static_cast<HBRUSH>(GetStockObject(BLACK_BRUSH)); //extra buffer windowClass.cbClsExtra = 0; windowClass.cbWndExtra = 0; //name to represent our window class windowClass.lpszClassName = progName; //we don't need menu windowClass.lpszMenuName = NULL; //register our class to windows if(!RegisterClass(&windowClass)) return 0; //create window HWND window; window = CreateWindowEx(WS_EX_TRANSPARENT, //allways on top of others progName, //name of window class progName, //text in the titlebar //no resizable window without minimize option WS_POPUP|WS_MINIMIZE|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX, //default window position 0, 0, //window width and height dx, dy, //no parent window NULL, //no menu NULL, hInstance, //no extra parameters NULL); //quit if we can't create a window if(!window) return 0; //show ShowWindow(window, nCmdShow); UpdateWindow(window); //process messages MSG message; while(GetMessage(&message, NULL, 0, 0)) { TranslateMessage(&message); DispatchMessage(&message); } return message.wParam; } LRESULT CALLBACK windowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { //window creation case WM_CREATE: { //set timer to get the pixel color if(!SetTimer(hwnd, timer, interval, NULL)) return 0; }break; //timer case WM_TIMER: { if(GetAsyncKeyState(0x61)) { KillTimer(hwnd, timer); PostQuitMessage(0); return 0; } InvalidateRect(hwnd, NULL, true); }break; //repaint case WM_PAINT: { //get the window device context for drawing PAINTSTRUCT ps; HDC windowDC; windowDC = BeginPaint(hwnd, &ps); //////////////////////////////////////////////////////////////////////////////////// LoadBMPIntoDC(windowDC); //////////////////////////////////////////////////////////////////////////////////// FindPixelred1(windowDC); //////////////////////////////////////////////////////////////////////////////////// /* keybd_event(0x2c, 0, 0, 0); keybd_event(0x2c,0, KEYEVENTF_KEYUP,0); Sleep(100);*/ ReleaseDC ( hwnd, windowDC ); // release dc DeleteDC(windowDC); EndPaint(hwnd, &ps); }break; case WM_DESTROY: { KillTimer(hwnd, timer); PostQuitMessage(0); return 0; }break; } return DefWindowProc(hwnd, message, wParam, lParam); }Viel Spaß!
-
masterslavemaster schrieb:
Viel Spaß!
Willst du mich verarschen?
Sowas lass ich mir doch nicht gefallen, ich klink mich aus...
-
masterslavemaster schrieb:
Codamieren
Das Wort gibt's nicht.
EIN KLEINER HINWEIS WÄRE NICHT SCHLECHT!
Hinweis: die Fehlerbeschreibung ist zu wirr. Der Beispielcode ist zu lange. Dein Auftreten hier ist zu "so und jetzt helft mir mal schön". Die erfundenen Wörter helfen auch nicht.
Vielen Dank!