Hi all,
i would like to scan a certain range of my desktop for a certain pixel colour
in always recurring distances. The whole should run in the background (i use WinXP
Prof) and as fast as possible. First i tried it with "GetPixel" (see the code with
GetPixel) and i could do it successfully. But the handicap is that with bigger
ranges "GetPixel" is simply to slow!
In the meantime i have read that there is a quicker possibility with "CreateDIBSection"
Now i tried to do the same work with "CreateDIBSectio" but i couldnt resovlve that
problem. Can anybody help me and give me a codesnippet that do the same work as the
GetPixel-code-example? It would be very very nice :-)
regards, rommi (C++ Beginner)
****** code with GetPixel ************
Code:
int x, y;
HDC dc = GetDC(0);
int seekpix = 16777215;
while(true)
{
for(x=100; x < 500; x++)
{
for(y=200; y < 800; y++)
{
//=========== Desktop-Pixelfarbe ermitteln
COLORREF deskpix = GetPixel(dc, y, x);
//=========== Desktop-Pixelfarbe mit Suchpixel vergleich
if(deskpix == seekpix)
{
//execute further code
}
}
}
}
****** my try with CreateDIBSection *****
Code:
// Deklaration
HDC hdc_screen;
BITMAPINFO bmi;
LPBYTE pBits;
int x=500;
int y=800;
// window-id
HWND desktopHandle = GetDesktopWindow();
// device-context
hdc_screen = GetDC(desktopHandle);
// clean
ZeroMemory(&bmi, sizeof(bmi));
// Parameter DIBSection
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = x;
bmi.bmiHeader.biHeight = y;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;
// Create DibSection
HBITMAP hdcBmp = CreateDIBSection(hdc_screen, &bmi, DIB_RGB_COLORS, (void **)&pBits, NULL, 0);
// ??????
// ??????