Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2233
  • Last Modified:

MFC Double buffering

I wanna make double buffering using MFC but i only know how do do it using
the #include "windows.h" , not with MFC.

can anyone help me? i've tryed to find tutorials and
sources on google but i've just found non MFC code


void CApplicationView::OnDraw(CDC* pDC)
{
     CTransCorpDoc* pDoc = GetDocument();
     ASSERT_VALID(pDoc);

    // i've put this code to help u

}

THANKS A LOT!!!!
0
ghuga
Asked:
ghuga
  • 2
1 Solution
 
jackrabbit22Commented:
Not tested for errors...

// Get clip box
CRect rcClipBox;
pDC->GetClipBox(rcClipBox);

// Create memory dc and update it's mapping state
CDC memDC;
memDC.CreateCompatibleDC(pDC);
memDC.SetMapMode(pDC->GetMapMode());
memDC.SetViewportOrg(pDC->GetViewportOrg());
memDC.IntersectClipRect(rcClipBox);

// Create memory bitmap
CBitmap bmp;
bmp.CreateCompatibleBitmap(pDC, rcClipBox.Width(), rcClipBox.Height());
CBitmap* pOldBmp = memDC.SelectObject(&bmp);

// Draw to memDC
memDC.TextOut(50, 50, _T("Whatever"));

// Blit to the original dc
pDC->BitBlt(rcClipBox.left, rcClipBox.top, rcClipBox.Width(), rcClipBox.Height(), &memDC, rcClipBox.left, rcClipBox.top, SRCCOPY);

// Restore old bitmap
memDC.SelectObject(pOldBmp);



0
 
jackrabbit22Commented:
forgot something...

Before you draw to the memory dc, fill the background.

memDC.FillSolidRect(rcClipBox, GetSysColor(COLOR_WINDOW));

also override OnEraseBackground and return TRUE

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now