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: 586
  • Last Modified:

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
0
fatimao
Asked:
fatimao
2 Solutions
 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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