HBITMAP bit;
HDC MemDC;
HDC DCBak;
CRect rect;
int w,h;
CString dir;
CString cc;
int p;
char appdir[256];
int m0;
int m1;
BOOL getpic(CString cc,int p);
BOOL loadbmp(CString cc);
void TransparentBlt2(HDC hdc0,
int nX0,int nY0,
int nW0,int nH0,
HDC hdc1,
int nX1,int nY1,
int nW1,int nH1,
UINT Tcol
);
定时器:
void ClearnDlg::OnTimer(UINT nIDEvent)
{
//添加一个定时器其实用处很简单 不定的加载不同的图片在同一个地方
CClientDC dc(this);
int x=200,y=200; //人物所处的起始位置
BitBlt(dc.m_hDC,x,y,100,100,DCBak,x,y,SRCCOPY);
//BitBlt(dc.m_hDC,0,0,640,480,DCBak,0,0,SRCCOPY);地图重复被加载
if(getpic("人",p)==FALSE)
AfxMessageBox(cc+"没找到!");
SelectObject(MemDC,bit);
TransparentBlt2(dc.m_hDC,x,y,w,h,MemDC,0,0,w,h,RGB(255,255,255));
p++;
if(p>m1) p=m0;
CDialog::OnTimer(nIDEvent);
}
转换透明的函数,还没看懂什么意思
void TransparentBlt2( HDC hdc0,
int nX0,int nY0,
int nW0,int nH0,
HDC hdc1,
int nX1,int nY1,
int nW1,int nH1,
UINT Tcol
)
{
HBITMAP hBMP =CreateCompatibleBitmap(hdc0,nW0, nH0);//创建一幅与设备有关位图,它与指定的设备场景兼容
HBITMAP mBMP =CreateBitmap(nW0,nH0,1,1,NULL);
HDC hDC =CreateCompatibleDC(hdc0);
HDC mDC =CreateCompatibleDC(hdc0);
HBITMAP oldBMP =(HBITMAP)SelectObject(hDC, hBMP);
HBITMAP oldmBMP=(HBITMAP)SelectObject(mDC, mBMP);
if (nW0==nW1&&nH0==nH1)
BitBlt(hDC,0,0,nW0,nH0,hdc1,nX1,nY1,SRCCOPY);
else
StretchBlt(hDC,0,0,nW0,nH0,hdc1,nX1,nY1,nW1,nH1,SRCCOPY);
SetBkColor(hDC, Tcol);
BitBlt(mDC,0,0,nW0,nH0,hDC,0,0,SRCCOPY);
SetBkColor(hDC, RGB(0,0,0));
SetTextColor(hDC, RGB(255,255,255));
BitBlt(hDC,0,0,nW0,nH0,mDC,0,0,SRCAND);
SetBkColor(hdc0,RGB(255,255,255));
SetTextColor(hdc0,RGB(0,0,0));
BitBlt(hdc0,nX0,nY0,nW0,nH0,mDC,0,0,SRCAND);
BitBlt(hdc0,nX0,nY0,nW0,nH0,hDC,0,0,SRCPAINT);
SelectObject(hDC, oldBMP);
DeleteDC(hDC);
SelectObject(mDC, oldmBMP);
DeleteDC(mDC);
DeleteObject(hBMP);
DeleteObject(mBMP);
}
void ClearnDlg::OnBnClickedOk()
{
CClientDC dc(this);
p=0;
m0=0;
m1=100;
MemDC = CreateCompatibleDC(0);//暂存设备场景
DCBak = CreateCompatibleDC(0);
GetCurrentDirectory(256,appdir);
dir=appdir;
//加载地图
cc=dir+"\图片\地面.bmp";
if(loadbmp(cc)==FALSE)
AfxMessageBox(cc+"没找到!");
SelectObject(DCBak,bit);
GetWindowRect(rect);
BitBlt(dc.m_hDC,0,0,640,480,DCBak,0,0,SRCCOPY);
SetTimer(1,150,NULL);
}
void ClearnDlg::OnBnClickedCancel()
{
// TODO: 在此添加控件通知处理程序代码
DeleteDC(MemDC);
DeleteObject(bit);
DeleteDC(DCBak);
OnCancel();
}