Advertisement

mfc, double buffers....DC's

Started by May 22, 2000 06:56 AM
4 comments, last by Arkon 23 years, 8 months ago
i''m looking for DOUBLE BUFFER sample... could anyone know where i may get one? thx
Here, I''ll whip one up. This is for a Doc-View format, overloading the OnDraw of the view:
MyClass::OnDraw (CDC* pDC){  CRect rcClip;  pDC->GetClipBox (&rcClip); // get bounds to be drawn  CDC bufDC;  bufDC.CreateCompatibleDC (pDC); // create buffer dc  // now, do anything you want with the bufDC...  // draw lines, copy bitmaps, whatever.  Let''s assume  // that you''re using the values int x and int y as your  // origin on the buffer DC.  // After you''re done...  // blit from buffer DC to screen DC  pDC->BitBlt (rcClip.left, rcClip.top, rcClip.Width (),               rcClip.Height (), &bufDC, x, y, SRCCOPY);  // de-select any objects from the bufDC that you have  // selected with SelectObject  // voila, done!} 

The ''x'' and ''y'' above are the origins you use in your buffer DC. If you keep a bitmap in memory of what the client area should look like, this will also be rcClip.left and rcClip.top. If you only draw the clipping area, they''ll probably be 0 and 0.

Hope that helps you get started. If this isn''t enough, post again and I''ll post a more specific example.

Advertisement
you rock
ir really helped...
don''t i need CBITMAP and stuff?

i guess it''s NOT like win 32....

now can you please show me triple buffering...

thx dude!
You can use a CBitmap if you want. Or CPens. Or CBrushes. This would all go in the place where I said, "now, do anything you want with the bufDC".

For instance, if you have a bitmap in memory you want to copy into the invalidated region, you''d do it this way:

CBitmap* pOldBmp = bufDC.SelectObject (m_pBmp);

...where m_pBmp is a CBitmap* in memory. When you do the pDC->BitBlt(), this bitmap will be copied to the screen.

Make sure after the blit you select the old bitmap:
bufDC.SelectObject (pOldBmp);

As for triple-buffering, I don''t know what that is. Sorry.
Triple buffering means to have a buffer of the background which is redrawn only when the background changes, a buffer for moving objects which is drawn every frame (after copying the background buffer to it) and the video buffer..


can you show an example of it in MFC?
Here is a tripple buffer example I am just now using in a custom
control CScreen. It is a CStatic subclass.

Tripple buffering works great. Only update the background when it scrolls/changes. If it just needs to be repainted you just call this method.


void CScreen::drawObjects()
{
CClientDC dcScr(this);

// blt LAND to WORK
dcWork.BitBlt(0,0,617,450,&dcLand,0,0,SRCCOPY);

// draw the man on WORK.
if (obj.isVisible(xOff,yOff))
dcWork.DrawIcon(pos_X[obj.getX(xOff)][obj.getY(yOff)],pos_Y[obj.getY(yOff)],man);

// copy WORK to SCREEN
dcScr.BitBlt(0,0,617,450,&dcWork,0,0,SRCCOPY);
ReleaseDC(&dcScr);
}



Forget trying to follow the code in the DrawIcon, it is just for testing a map obj class on a hex type map. Just read DrawIcon(x,y,cx,cy,icon).


- Woodie Dovich

This topic is closed to new replies.

Advertisement