With The Case Of  Release The Power OF  Visual C++ !   HomeProducts | PurchaseSupport | Downloads  
Download Evaluation
Pricing & Purchase?
E-XD++Visual C++/ MFC Products
Features Tour 
Electronic Form Solution
Visualization & HMI Solution
Power system HMI Solution
CAD Drawing and Printing Solution

Bar code labeling Solution
Workflow Solution

Coal industry HMI Solution
Instrumentation Gauge Solution

Report Printing Solution
Graphical modeling Solution
GIS mapping solution

Visio graphics solution
Industrial control SCADA &HMI Solution
BPM business process Solution

Industrial monitoring Solution
Flowchart and diagramming Solution
Organization Diagram Solution

Graphic editor Source Code
UML drawing editor Source Code
Map Diagramming Solution

Architectural Graphic Drawing Solution
Request Evaluation
ActiveX COM Products
Technical Support
  General Q & A
Discussion Board
Contact Us


Get Ready to Unleash the Power of UCanCode .NET


UCanCode Software focuses on general application software development. We provide complete solution for developers. No matter you want to develop a simple database workflow application, or an large flow/diagram based system, our product will provide a complete solution for you. Our product had been used by hundreds of top companies around the world!

"100% source code provided! Free you from not daring to use components because of unable to master the key technology of components!"


GDI Topics: Flicker-Free Drawing




If you display a picture or draw a shape in a device context using CDC, when the view is resized, there a nasty effect of a double drawing that shows some gray or white sections over the actual drawing area. This is referred to as flicker.

Practical Learning Practical Learning: Producing Flickering 



  1. To produce the flicker effect, create an MFC Application named FlickerFree
  2. Create it as a Single Document type
  3. Using the Resource Symbols dialog box, create an ID named IDT_OCCUR
  4. In the view header file, declare the following variables:
    // FlickerFreeView.h : interface of the CFlickerFreeView class
    #pragma once
    class CFlickerFreeView : public CView
    protected: // create from serialization only
    // Attributes
    	CFlickerFreeDoc* GetDocument() const;
    // Operations
    // Overrides
    	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
    	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
    	virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
    	virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
    	virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
    // Implementation
    	virtual ~CFlickerFreeView();
    #ifdef _DEBUG
    	virtual void AssertValid() const;
    	virtual void Dump(CDumpContext& dc) const;
    // Generated message map functions
    	int x;
    	int y;
    	int w;
    	int h;
    	BOOL MovingRight;
    #ifndef _DEBUG  // debug version in FlickerFreeView.cpp
    inline CFlickerFreeDoc* CFlickerFreeView::GetDocument() const
       { return reinterpret_cast<CFlickerFreeDoc*>(m_pDocument); }
  5. In the constructor of the view class, initialize the variables as follows:
    	// TODO: add construction code here
    	x = 0;
    	y = 100;
    	w = 100;
    	h = 150;
    	MovingRight = TRUE;
  6. Generate the OnInitialUpdate event for the view class and use it to initialize the timer as follows:
    void CFlickerFreeView::OnInitialUpdate()
    	// TODO: Add your specialized code here and/or call the base class
    	SetTimer(IDT_OCCUR, 10, NULL);
  7. Change the OnDraw event as follows:
    void CFlickerFreeView::OnDraw(CDC* pDC)
    	CFlickerFreeDoc* pDoc = GetDocument();
    	if (!pDoc)
    	// TODO: add draw code for native data here
    	CRect rect;
    	CBrush brsBlack, *brsOld;
    	brsBlack.CreateSolidBrush(RGB(0, 0, 0));
    	brsOld = pDC->SelectObject(&brsBlack);
    	pDC->Rectangle(rect.left,, rect.Width(), rect.Height());
    	CPen   penRed, *penOld;
    	penRed.CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
    	penOld = pDC->SelectObject(&penRed);
    	pDC->Rectangle(x, y, x + 100, h);
  8. Generate the event of the WM_TIMER message for the view class and implement it as follows:
    void CFlickerFreeView::OnTimer(UINT_PTR nIDEvent)
    	// TODO: Add your message handler code here and/or call default
    	CRect rect;
    	if( x < 0 )
    		x = 0;
    		MovingRight = TRUE;
    	if( x > (rect.Width() - 100) )
    		x = rect.Width() - 100;
    		MovingRight = FALSE;
    	if( MovingRight == TRUE )
  9. Execute the application to see the result and notice the flickering effect
  10. Close the application

Flicker Free


Fortunately, in most cases, getting rid of, or reducing, the flickering effect can be easy. To take care of it, override the OnEraseBkgnd event and simply return TRUE from it.

Practical Learning Practical Learning: Taking Care of Flickering 

  1. Generate the event of the WM_ERASEBKGND message of the view class and change its return value as follows:
    BOOL CFlickerFreeView::OnEraseBkgnd(CDC* pDC)
    	// TODO: Add your message handler code here and/or call default
    	return TRUE;// CView::OnEraseBkgnd(pDC);
  2. Execute the application again to see the result



Copyright ?1998-2009 UCanCode.Net Software , all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to