flickering problem - invalidate function

Posted on 2005-05-11
Last Modified: 2013-11-20
   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.

Question by:fatimao
    LVL 55

    Accepted Solution

    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;

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

          dc.BitBlt(0, 0, rect.right, rect.bottom, &NoFlick, 0, 0, SRCCOPY);

    YourDrawFunction(CDC *pDC)
        // Do all your drawing here
    LVL 3

    Assisted Solution

    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();
        // TODO: add draw code for native data here - use pDC
         //as the device context to draw to

    Download the CmemnDC from

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    How to determine file rename from EventLog ? 2 33
    lucky13 challenge 11 95
    sum28 challenge 31 82
    isEverywhere  challenge 19 48
    Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
    Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now