Jump to content
  • Advertisement
Sign in to follow this  

finding bitmap in window

This topic is 4649 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)
			if ( j == bitmap1.bmHeight )
			  // Found

	printf("%d", NumOfFounds);
If anyone could shed any light on the situation i'd be very grateful, Thanks, David

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!