nav-left cat-right
cat-right
Matthias Pospiech > Programming > C++ > MFC > Flicker Free example with CStatic Control

Flicker Free example with CStatic Control

The following code shows how to paint into a CStatic Control and make sure this painting is flicker-free.

  1. Overloading of CStatic
The example code for download:   FlickerFreeDemoStatic.zip (61,6 KiB)

Overloading of CStatic

Unfortunately one can not draw inside a CStatic control directly. Therefore one need to overload the CStatic class an do the following (let CGraphCtrl be the overloaded class)

  1. make CGraphCtrl know what has to be draw (pass the data)
  2. Invalidate the content of CGraphCtrl and call UpdateWindow
  3. Each UpdateWindow results in OnPaint being processed. Inside this function we can now do the painting we have remembered to do

The calls presented here saves its data in

vector<vector <COLORREF> > PlotData;

and includes methods for resizing

	void Resize(const unsigned short width, const unsigned short height);
	void FullResize(const CRect newRect);
	void SetSize(const unsigned short width, const unsigned short height);
	void SetPlotDataSize(const int x, const int y);
	CRect GetSize();
	CRect GetPlotDataSize();

and the actual painting

	void SetPlotData(vector</vector><vector <COLORREF> > InputArray);
	void UpdatePlot();
	void PaintPixel(CMemDC* pDC, const int x, const int y, COLORREF c);
	void PlotToDC(CMemDC* pDC);

Seiten: 1 2 3

Einen Kommentar schreiben

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

*

This blog is kept spam free by WP-SpamFree.