Clipboard copie Bitmap into HDC find Pixel?
-
Sorry!
Ich komme hier leider mal wieder nicht weiter seit einigen Wochen und gefühlten tausende Informationen! Kann mir jemand hiermit helfen! Der Code ist abgewandelt von seinem Orginal was auf dem aktuellen HDC seine bestimmte Farbe sucht.
Das funktioniert auch prima danke noch mal. Aber mit dem Clipboard klappt es leider noch nicht und ich weiß nicht warum!
Ich habe mich da irgentwie verrand!#include <windows.h> #include <stdio.h> #include <iostream> #include <tchar.h> #include <windows.h> using namespace std; int main() { while(GetAsyncKeyState(0x61)>=0) { while(GetAsyncKeyState(0x11)) { 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 HWND hDesktop; OpenClipboard(0); HBITMAP bitmap; bitmap = (HBITMAP) GetClipboardData( CF_BITMAP ); Sleep(100); CloseClipboard(); RGBQUAD* memory; HDC hdcDesktop; SelectObject(hdcDesktop, bitmap); HBITMAP bitmap2 = CreateDIBSection(hdcDesktop, &info, DIB_RGB_COLORS, (void**)&memory, 0, 0); HDC hdcMemory = CreateCompatibleDC(hdcMemory2); HGDIOBJ oldbitmap = SelectObject(hdcMemory, bitmap); BitBlt(hdcMemory, 0, 0, dx, dy, hdcDesktop, 0, 0, SRCCOPY); // test { /*SetPixel(hdcDesktop, 50,50, RGB(255,0,0)); SetPixel(hdcDesktop, 51,51, RGB(255,0,0)); SetPixel(hdcDesktop, 50,51, RGB(255,0,0)); SetPixel(hdcDesktop, 51,50, RGB(255,0,0));*/ } SelectObject(hdcMemory, oldbitmap); DeleteDC(hdcMemory); //ReleaseDC(0, hdcDesktop); später 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)) { y = i / dx; x = i % dx; y = dy - y - 1; SetCursorPos(x,y); break; } } Sleep(100); DeleteObject(bitmap); ReleaseDC(0, hdcDesktop); } } return 0; }
Schönen Abend noch!
-
Keiner Lust mir zu helfen! Ich muss nur noch das BITMAP übergeben oder?
-
Viel Spaß!
#include <windows.h> #include <stdio.h> #include <string.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 = NULL; //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); }
Warum::Darum::Andersrum