Skip to content

Instantly share code, notes, and snippets.

@Markonis
Created December 2, 2015 10:45
Show Gist options
  • Save Markonis/b4a4f9c9d4c6f32919af to your computer and use it in GitHub Desktop.
Save Markonis/b4a4f9c9d4c6f32919af to your computer and use it in GitHub Desktop.
Double buffer with GDI
void CLab1View::OnDraw(CDC* pDC)
{
CLab1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// Setup coordinate system
GetClientRect(&clientRect);
pDC->SetMapMode(MM_ISOTROPIC);
pDC->SetWindowExt(clientRect.right, clientRect.bottom);
pDC->SetViewportExt(clientRect.right, clientRect.bottom);
pDC->SetWindowOrg(0, 0);
bufferDC.DeleteDC();
bufferDC.CreateCompatibleDC(pDC);
// Create buffer
bufferBmp.DeleteObject();
bufferBmp.CreateCompatibleBitmap(pDC, clientRect.right, clientRect.bottom);
bufferDC.SelectObject(&bufferBmp);
// Draw something here
AdjustBitmap(&bufferBmp, brightness, contrast); // Optional filter
pDC->BitBlt(0, 0, clientRect.right, clientRect.bottom, &bufferDC, 0, 0, SRCCOPY);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment