4

I think the drawing now is not flickering anymore so I think it works,

But I have also one toolbar and one statusbar which now started to flicker heavily.

Is there any way to fix this?

BOOL CPaintDlg::OnEraseBkgnd(CDC* pDC) // redraw the background colors
{
    return true;
}

void CPaintDlg::OnPaint()
{
   CRect rcClient;
   GetClientRect(rcClient); 

   CDC MemDC, *pDC;
   CBitmap MemBitmap;

   pDC = this->GetDC();         // Get Current DC
   MemDC.CreateCompatibleDC(pDC);
   MemBitmap.CreateCompatibleBitmap(pDC, rcClient.right, rcClient.bottom);

   CBitmap *pOldBitmap = (CBitmap*)MemDC.SelectObject(&MemBitmap);

   MemDC.FillSolidRect(0, 0, rcClient.right, rcClient.bottom, RGB(255, 255, 255));

   for (int i = 0; i < myShapes.GetSize(); ++i)
       myShapes[i]->draw(&MemDC);

   pDC->BitBlt(0, 0, rcClient.right, rcClient.bottom, &MemDC, 0, 0, SRCCOPY);
   MemDC.SelectObject(pOldBitmap);

   ReleaseDC(pDC);
   ReleaseDC(&MemDC);

   CDialogEx::OnPaint();
}

Edit: Maybe it's because im drawing to the all ClientRect?

Is there a way to exclude the part of the toolbars, maybe with ExcludeClipRect?

Dannz
  • 495
  • 8
  • 20
  • Why aren't you using a `CPaintDC` in your `OnPaint()` implementation? At the very least, this ensures that clipping is properly set up. – IInspectable Jan 17 '17 at 10:17
  • I'm to confused about how to implement those stuff, Could you point me to the right direction? Shouldn't I draw to the buffer and then put if to the screen? – Dannz Jan 17 '17 at 10:30
  • 2
    MFC is hard to use. So the right direction would be to learn MFC properly, from the ground up. This requires, that you also learn how to do Windows API programming. There aren't any shortcuts. I've written about this here: [Prerequisites for learning MFC programming](http://stackoverflow.com/q/18165076/1889329). – IInspectable Jan 17 '17 at 10:40
  • 1
    Mfc now has a CMemDC class designed for double buffering. Draw into that. See https://msdn.microsoft.com/en-gb/library/cc308997(v=vs.100).aspx – Andrew Truckle Jan 17 '17 at 13:36
  • @IInspectable The part about changing my code to CPaintDC, can you explain this, please? – Dannz Jan 17 '17 at 17:35
  • 1
    Don't use the pDC variable you declared and initialized with GetDC(). Instead declare a variable like `CPaintDC paintDC(this);` and use &paintDC in the places where you used pDC. CPaintDC will do it the right way for your OnPaint() handler including clipping, etc, as mentioned by @IInspectable – Joseph Willcoxson Jan 17 '17 at 20:07
  • Unfortunately it doesn't work this way, It has more flicker now, And the background above my paintings is white. – Dannz Jan 18 '17 at 21:02
  • Assuming that you are working with CDialog, have you tried to check clip child's option ? – Flaviu_ Aug 02 '18 at 12:32

0 Answers0