/* 本段程序实现了将小图片拼接成大图片的过程,所建立的程序模版是基于对话框的程序。程序段放在了OnEraseBkgnd中了;并且使用了随机生成图片的方法,小图片的尺寸为50*50*/
#define rdint(i)(rand()%(int)(i)) //随机数定义
#define nRows 10 //生成地图的行数
#define nCols 6 //生成地图的列数
BOOL CMapDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CDC memdc,bufdc;
memdc.CreateCompatibleDC(pDC);
bufdc.CreateCompatibleDC(pDC);
HBITMAP bm[3];
CBitmap fullMap;
fullMap.CreateCompatibleBitmap(pDC,50*nCols,50*nRows);
CString strBmpPath;
int i;
for(i=0;i<3;i++)
{
strBmpPath.Format("res//map%d.bmp",i);
bm[i]=(HBITMAP)LoadImage(NULL,strBmpPath,IMAGE_BITMAP,50,50,LR_LOADFROMFILE);
}
memdc.SelectObject(&fullMap);
int pos[nCols*nRows];
for(i=0;i<nCols*nRows;i++)
{
pos[i]=rdint(2);
}
for(int j=0;j<nRows*nCols;j++)
{
int xStart,yStart;
int x,y;
x=j%nCols;
y=j/nCols;
xStart=x*50;
yStart=y*50;
bufdc.SelectObject(CBitmap::FromHandle(bm[pos[j]]));
memdc.BitBlt(xStart,yStart,50,50,&bufdc,0,0,SRCCOPY);
}
pDC->BitBlt(0,0,50*nCols,50*nRows,&memdc,0,0,SRCCOPY);
// return CDialog::OnEraseBkgnd(pDC);
return TRUE;
}