Re: howto avoid cdc drawing done not in onPaint to be erased?
"Equilibrium" <email@example.com> wrote in message
The reason i need all of this to perform outside the WM_PAINT message
is because the control is updated each 20ms with new object to
draw. the static control main goal is to display a tracking data , so
i recive x.y coordinates each 20ms , and on those coordinates
i need to draw something.
Storing those x,y in a string or an array and then caling WM_PAINT
(via invalidate) , and there to draw them, seems to me quite
expensive / wasteful , especially that the data can flow to the system
for along time.
The way you're doing it now has some problems. Since you're dropping
everything and drawing your static control every time you get x,y data, if
your drawing takes a long time, then you will start to get a queue of x,y
coords to draw because you can't keep up with them. That's the benefit of
doing all the drawing in WM_PAINT. Call InvalidateRect() as David Webber
suggests, specifying only the rect containing the new x,y coord that has
changed. That way you don't have to paint your entire control, saving time.
Windows will call OnPaint() to paint as it has time. The CPaintDC that is
used in OnPaint() has a PAINTSTRUCT member you can look at to see the rect
that is invalid and only paint that one, so it can be very efficient.
So if you keep receving data too fast and not letting Windows paint, your
static control will never be painted. To ensure it is painted, call
UpdateWindow(), which forces your OnPaint() to be called immediately. But
only do it every n points or else your drawing will again bog down.
In othere word what you are saying is, that if we are using the mouse
to free draw on a control ' we need to save each and every point the
mouse x,y position was.
Yes, all these points are necessary to reconstruct your static control when
it needs to be resized to stretch over a larger or smaller rect than before.
All the points can also be used to repainte from scratch when it is
minimized and restored.
If you control is not resizeable, then technically you could use a MemDC to
retain the image, but... see below.
What i need , basically is a way , when the disaplay need to be
"refresh\repaing" , to save the DC , and then restore it on WM_PAINT.
This assumes it is faster to blt the Mem DC instead of drawing just the
changed part in OnPaint(). Maybe that's not a good assumption. Usually Mem
DC's are only used to avoid flicker when your control is erased and painted
with the same contents. But this is slower, for a fact. You need to
execute the same drawing code to draw the MemDC, then you need to blt the
MemDC. This is slower than just executing the drawing code and that's it.