Original Post
i am attempting to load the calculator window image into an array of bits, load a small image which represents a portion of the calculator window, and check whether this small image resides within the larger one. i came up with some code which i thought did this, but it only works for some small images and not others. I was wondering whether some one could tell me why. I did think maybe that it was because i was comparing a DIB(the smaller image) to a DDB, but i am not entirely clear about this (i am new to bitmaps etc...) code:
// small image
HANDLE hBitMap1 = ::LoadImage(0, _T("c:\\tttt.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
BITMAP bitmap1;
::GetObject(hBitMap1, sizeof(BITMAP), &bitmap1);
int SmallBps = bitmap1.bmBitsPixel / 8;
int smallSize = bitmap1.bmHeight * bitmap1.bmWidth * SmallBps;
BYTE *smallBytes = new BYTE[smallSize];
::GetBitmapBits((HBITMAP)hBitMap1, smallSize, smallBytes);
RECT rc;
HWND hWnd = ::FindWindow(0, _T("Calculator"));
if(!hWnd) return;
::GetWindowRect (hWnd, &rc);
HDC hDC = ::GetDC(0);
HDC memDC = ::CreateCompatibleDC(hDC);
HBITMAP memBM = ::CreateCompatibleBitmap(hDC, rc.right-rc.left, rc.bottom-rc.top);
HBITMAP OldBM = (HBITMAP)::SelectObject(memDC, memBM);
::BitBlt(memDC, 0, 0, rc.right-rc.left, rc.bottom-rc.top, hDC, rc.left, rc.top, SRCCOPY);
int BigBps = ::GetDeviceCaps(hDC, BITSPIXEL)/8;
int Width = rc.right-rc.left;
int Height = rc.bottom-rc.top;
int size = BigBps * (Width * Height);
BYTE *bigBytes = new BYTE[size];
::GetBitmapBits(memBM, size, bigBytes);
int NumOfFounds = 0;
int j;
for(int i = 0; i < Height; i ++)
{
for(int hh = 0; hh < Width; hh ++)
{
for(j = 0; j < bitmap1.bmHeight; j ++)
{
int PosOnSmall = j * bitmap1.bmWidth * SmallBps;
int PosOnBig = (i*Width * BigBps) + (hh*BigBps)+ j * Width * BigBps;
int SmallLineWidth = bitmap1.bmWidth * SmallBps;
if(memcmp(&bigBytes[PosOnBig], &smallBytes[PosOnSmall], SmallLineWidth) != 0)
break;
}
if ( j == bitmap1.bmHeight )
{
// Found
NumOfFounds++;
}
}
}
printf("%d", NumOfFounds); If anyone could shed any light on the situation i'd be very grateful, Thanks, David