今天搞了下画图。。。。
没有实现自己想要的结果。。。
总有闪烁的问题。。。。明天来解决了。。。要熄灯了
BOOL CDBufferDlg::OnEraseBkgnd( CDC* pDC )
{
CDC MemDc;
CRect rt;
this->GetClientRect(&rt);
MemDc.CreateCompatibleDC(pDC);
MemDc.SelectObject(&m_Bitmap[0]);
// pDC->BitBlt(0,0,m_hBitmap[0].bmWidth,m_hBitmap[0].bmHeight,&MemDc,0,0,SRCCOPY);
pDC->StretchBlt(0,0,rt.Width(),rt.Height(),&MemDc,0,0,m_hBitmap[0].bmWidth,m_hBitmap[0].bmHeight,SRCCOPY);
return FALSE;
}
void CDBufferDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CRect rt;
GetClientRect(&rt);
switch(nChar)
{
case 'W':
{
if (y>rt.top&&y<rt.bottom)
{
y = y-m_Speed;
}
m_Mode = UP;
SetBitmap(UP);
}
break;
case 'S':
{
if (y<rt.bottom-40&&y>=rt.top)
{
y = y+m_Speed;
}
m_Mode = DOWN;
SetBitmap(DOWN);
}
break;
case 'A':
{
if (x>rt.left&&x<=rt.right)
{
x = x-m_Speed;
}
m_Mode = LEFT;
SetBitmap(LEFT);
}
break;
case 'D':
{
if (x>=rt.left&&x<rt.right-40)
{
x = x+m_Speed;
}
m_Mode = RIGHT;
SetBitmap(RIGHT);
}
break;
default:
break;
}
// InvalidateRect(&rt,TRUE);
CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CDBufferDlg::SetBitmap(Mode mode)
{
CRect rt;
GetClientRect(&rt);
CDC memDC;
CDC *pDC = GetDC();
memDC.CreateCompatibleDC(pDC);
memDC.SelectObject(&m_Bitmap[mode]);
int i = pDC->SaveDC();
CRgn rgn;
rgn.CreateRectRgn(0,0,m_hBitmap[mode].bmWidth,m_hBitmap[mode].bmHeight);
pDC->SelectClipRgn(&rgn);
pDC->BitBlt(x,y,m_hBitmap[mode].bmWidth,m_hBitmap[mode].bmHeight,&memDC,0,0,SRCCOPY);
pDC->RestoreDC(i);
pDC->BitBlt(x,y,m_hBitmap[mode].bmWidth,m_hBitmap[mode].bmHeight,&memDC,0,0,SRCCOPY);
}