Dave Sexton said:
Hi Michael,
But for scrolling text you can't draw everything only once. It's
scrolling!
As Michael notes, in theory as long as you ensure that every pixel that
needs to change is drawn, you can avoid the flickering.
However...it's MUCH harder to accomplish this, and in some cases may be
impossible of course. Even with the original GDI, while it might have been
theoretically possible to draw the text, and fill the region outside the
text with the background color, that would have been such an expensive
drawing operation, no one sensible person would have done it that way.
The most common solution would have been to simply maintain a bitmap the
same size as the on-screen window, drawing into that and then blting the
results to the screen. Another solution would be to use smaller bitmaps,
the size of whatever it is you want to draw, blt those as they are drawn to
the appropriate spot on the screen. Of course, as was noted in Michael's
earlier post, if the kinds of things that are being drawn lend themselves to
simply copy an entire image to fill a specific area on the screen, then that
works too.
The key in all solutions is to avoid first clearing an area on the screen
and then drawing something else on top of that.
BTW, you can draw text with a background color in the 2.0 framework using
the TextRenderer class, which I believe uses GDI, not GDI+.
It's been awhile, but my recollection is that this doesn't make a
difference. That is, when drawing text with a background color (using the
opaque style), GDI would first fill in the background and then draw the
text, all directly to the destination DC. It didn't avoid flickering...it
just was more convenient than calling FillRect directly yourself (and also
had the advantage that you didn't have to measure the text first, since the
TextOut function handled the whole thing for you).
Even if using "double buffering" (sorry, I still hate that term as applied
here) could be avoided and dealing with updating screen graphics could be
solved some other way, IMHO there's not really any great reason to do so.
Using an off-screen bitmap, as in "double buffering", is a reasonably
elegant way to address a variety of complications that come up with any sort
of animated or changing display, and with the amount of RAM available on
most systems these days, doesn't incur much of a penalty.
Pete