bool FindPic(int x,int y,int xx,int yy, CString FileName, double s, int &rex,int &rey)
{
CBitmap bmp;
BITMAP   bm;
HBITMAP  hBmp;
CDC   bmpDC;
hBmp = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),FileName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
bmp.DeleteObject();
bmp.Attach( hBmp );
bmp.GetObject(sizeof(BITMAP),&bm);  
bmpDC.CreateCompatibleDC(NULL);  
bmpDC.SelectObject(&bmp); //图片DCHDC hScreenDC = ::GetDC(NULL); //屏幕DC
bool found = false;//是否匹配到bool next = false;//是否找下一个点int width = bm.bmWidth;
int height = bm.bmHeight;
int limit = (double)(width * height) * (1-s);
int count = 0;for (int i = x; i < (xx - width) && !found ; i++)
{
for (int j = y ; j < (yy - height) && !found ; j++)
{
next = false;
count = 0;
for (int a = 0;a<width && !next;a++)
{
for (int b = 0;b<height &&!next;b++)
{
if(GetPixel(hScreenDC,i+a,j+b) != bmpDC.GetPixel(a, b))
{
//next = true;//找屏幕中下一个点
count ++;
}
if (count > limit)
{
next = true;
}
}
}
if (!next)//找到点
{
found = true;
rex = i;
rey = j;
return true;
break;
}
}
}
return false;
}