flickering problem - invalidate function

hi,
   i am currently working on a chess project. I have used the fuction Invalidate() to reflect each move of piece. But the consequece is that the whole screen is redrawn on each move ... specially on MouseMove() function where invalidate is called at each point moved.
Kindly tell an alternate solution ... to avoid flickering.

regards
fa
fatimaoAsked:
Who is Participating?
 
Jaime OlivaresSoftware ArchitectCommented:
you need a flicker free technique:

Modify your OnPaint or OnDraw event, similar to this:

void CMainFrame::OnPaint()
{
      CPaintDC dc(this); // device context for painting
      CDC NoFlick;
      CBitmap bmp, *oldBmp;
      CRect rect;

      NoFlick.CreateCompatibleDC(&dc);
      GetClientRect(&rect);
      bmp.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height());
      oldBmp = NoFlick.SelectObject(&bmp);

      YourDrawFunction(&NoFlick);
      
      dc.BitBlt(0, 0, rect.right, rect.bottom, &NoFlick, 0, 0, SRCCOPY);
      NoFlick.SelectObject(*oldBmp);
}

YourDrawFunction(CDC *pDC)
{
    // Do all your drawing here
}
0
 
NawalKishore1976Commented:
Override the EraseBkgnd
BOOL CExampleView::OnEraseBkgnd(CDC* pDC)
{
      // TODO: Add your message handler code here and/or call default
      return CView::OnEraseBkgnd(pDC);
}
 
// To this code
BOOL CExampleView::OnEraseBkgnd(CDC* pDC)
{
      return FALSE;
}
Change your OnDraw code to the following: void CExampleView::OnDraw(CDC* dc)
{
    CMemDC pDC(dc);
    CExampleDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here - use pDC
     //as the device context to draw to
}

Download the CmemnDC from CodeProject.com
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.