The following code shows how to paint into a CStatic Control and make sure this painting is flicker-free.
[TOC] 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)
- make CGraphCtrl know what has to be draw (pass the data)
- Invalidate the content of CGraphCtrl and call UpdateWindow
- 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); |