So, I know that people talk about double buffering on different posts, but whenever I try it I get a black screen! this is because the examples I see (I need examples) don't program the way i do - like with different libraries. I only use at the moment. anyways, here is the initial program piece which badly flickers:
void drawRed (HDC hdc)
{
HDC hdcMemory;
hdcMemory = CreateCompatibleDC(hdc);
while (1==1){
SelectObject(hdcMemory, redmask);
BitBlt(hdc, 132, 132, 128, 128, hdcMemory, 0, 0, SRCAND);
SelectObject(hdcMemory, red);
BitBlt(hdc, 132, 132, 128, 128, hdcMemory, 0, 0, SRCPAINT);
}
DeleteDC(hdcMemory);
}
and I looked and tried this:
void drawRed (HDC hdc)
{
HDC hDC = GetDC(hnd);
HDC hdcMemory;
hdcMemory = CreateCompatibleDC(hdc);
HDC memDC = CreateCompatibleDC(hDC);
HBITMAP hMemBmp = CreateCompatibleBitmap(hDC,100,100);
HBITMAP hOldBmp = (HBITMAP)SelectObject(memDC,hMemBmp);
SelectObject(hdcMemory, hbmMem);
BitBlt(hDC, -100, -100, 128, 128, memDC, 0, 0, SRCAND);
SelectObject(hdcMemory, red);
BitBlt(hDC, -100, -100, 128, 128, memDC, 0, 0, SRCPAINT);
SelectObject(hdcMemory, red);
BitBlt(hDC, 132, 132, 128, 128, memDC, 0, 0, SRCCOPY);
DeleteDC(hdcMemory);
}
and this just shows a black box. I don't know how I'm supposed to do it, so can you change the original code block to be double-buffered? thanks!
I use dev-c++ ide.
For MFC you can use class CMemDC by Keith Rule. There is good article about this class with example - http://www.codeproject.com/Articles/33/Flicker-Free-Drawing-In-MFC
Similar class included in MFC Feature Pack - http://msdn.microsoft.com/en-us/library/cc308997.aspx