Re: Double Buffer A Custom Control
Double buffering is a very simple concept. Instead of drawing on the actual
screen dc you would draw all your pieces on a memory dc (one that is not
attached to a window) and when you are done you would bitblt it on the
screen dc.
So you what you would have to do is:
1. Create a memory dc
CDC MemDC;
MemDC.CreateCompatibleDC(&paintdc);
int SavedDC = MemDC.SaveDC();
2. Create a memory bitmap to select into the memory dc, and select it into
the memory dc
CBitmap Bmp;
Bmp.CreateCompatibleBitmap(&paintdc,Width,Height);
MemDC.SelectObject(&Bmp);
3. Now do your drawing to the MemDC instead of paintdc.
4. Then bitblt everything into the paintdc
paintdc.BitBlt(0,0,Width,Height,MemDC,0,0,SRCCOPY);
5. restore the memdc.
MemDC.RestoreDC(SavedDC);
But here is a class that will simplify things for you.
http://www.codeproject.com/KB/GDI/flickerfree.aspx
Also make sure to read about WM_ERASEBKGND.
AliR.
<davep15@gmail.com> wrote in message
news:983d9fc7-525f-4d1b-b809-426fb06a418c@r3g2000vbp.googlegroups.com...
First off I'd like to make it clear that programing with MFC is
somewhat new to me, I've done some basic stuff with it before but
windows (or any OS for that matter) programing isn't usually where I
program.
I'm using Visual Studio 2005 Professional
I have been working on creating my own custom line graph control to
suite my needs and have it working pretty well, one issue I'm having
though is flashing effect when changing things rapidly, I need to add
double buffering to the paint routine but not sure how to do it in
this case.
I've been using this as my how to guild up to know but it doesn't have
any double buffering examples
http://www.codeproject.com/KB/dialog/selfregister.aspx?display=Print
The DC I'm doing my drawing to is of the CPaintDC type and I'd like my
memory DC to also be of that type.