双缓冲是可以,但是最好还是用DDraw来做,或者d3d ddraw/d3d直接访问显存,速度更快一些双缓冲的例子很多的 CRect rcClient; GetClientRect(rcClient); // See Note 1 CDC MemDC,*pDC; CBitmap MemBitmap; pDC = this->GetDC() // Get Current DC MemDC.CreateCompatibleDC(pDC); MemBitmap.CreateCompatibleBitmap(pDC,rcClient.right,rcClient.bottom); CBitmap *pOldBitmap = MemDC.SelectObject(&MemBitmap); CBrush bkBrush(HS_FDIAGONAL,RGB(0,rand()%255,0)); // See Note 2 MemDC.FillRect(rcClient,&bkBrush); pDC->BitBlt(0,0,rcClient.right,rcClient.bottom,&MemDC,0,0,SRCCOPY); //See Note 3 MemDC.SelectObject(pOldBitmap);Note 1 : Gets the coordinates of the bounding rectangle. Note 2 : Creates a brush with random shades of green. The rand()%255 generates a value between 0 and 255 randomly. Note 3 : Copies the bitmap from the memory dc to the pdc using a fast bitblt function call.
就是先画在一个内存DC上
再画在设备DC上例,
OnDraw(CDC *pDC)
{
CDC *MemDC;
MemDC->.....;
pDC->BitBlt(0,0,400,400,&MemDC,0,0,SRCCOPY);
}
ddraw/d3d直接访问显存,速度更快一些双缓冲的例子很多的
CRect rcClient;
GetClientRect(rcClient); // See Note 1 CDC MemDC,*pDC;
CBitmap MemBitmap; pDC = this->GetDC() // Get Current DC
MemDC.CreateCompatibleDC(pDC);
MemBitmap.CreateCompatibleBitmap(pDC,rcClient.right,rcClient.bottom); CBitmap *pOldBitmap = MemDC.SelectObject(&MemBitmap);
CBrush bkBrush(HS_FDIAGONAL,RGB(0,rand()%255,0)); // See Note 2
MemDC.FillRect(rcClient,&bkBrush); pDC->BitBlt(0,0,rcClient.right,rcClient.bottom,&MemDC,0,0,SRCCOPY); //See Note 3
MemDC.SelectObject(pOldBitmap);Note 1 : Gets the coordinates of the bounding rectangle.
Note 2 : Creates a brush with random shades of green. The rand()%255 generates a value between 0 and 255 randomly.
Note 3 : Copies the bitmap from the memory dc to the pdc using a fast bitblt function call.