Window freezing when drawing rectangles repeatedly

Hi,

I have performance problems doing the following:

I'm writing a Borland c++ software that displays objects (little rectangles) moving around.
I'm using the standard windows API, no MFC or anything similar encapsulating it.

With every WM_TIMER event (0.1 sec) I call a function, that
- for all objects calculates positions (float) not corresponding to the window,
- then "resets" the window by getting ClientRect and brushing it white
- then draws all objects on the screen (rectangle() function) calculating their new position on the window (short). HSCROLL and VSCROLL are taken into consideration by subtracting the values from x and y.

The problem is, that the window freezes from time to time
(freezing frequency increases no wonder with the number of objects drawn).
While this happens my function however is repeatedly called by subsequent WM_TIMERs. I can see that by watching the continuous outputs of my debug couts in the dos box. That means my function is not stopping or waiting. It keeps on doing all redrawing that I can't see during freeze.

The couts don't seem to be the problem, since I get no improvement by suppressing them.

Maybe I could get an improvement by only erasing the objects to redraw but that would involve storing their old position and repeated invocation of an erasure function. Apart from that I would probably get dirt effects due to rounding.

Any idea, how to optimize the drawing or how to approach the problem in general ?

Thanks a lot

Bapon
[1610 byte] By [bapon] at [2007-11-18 19:17:03]
# 1 Re: Window freezing when drawing rectangles repeatedly
What do you mean by freezes ?
You may want to use memory DC to first draw and then transfer it to screen DC.
kirants at 2007-11-9 13:09:54 >
# 2 Re: Window freezing when drawing rectangles repeatedly
First: Thanks for your reply.

When saying freeze, I mean, that my objects are not redrawing during that time. That's all.

How do I use memory DC ?
bapon at 2007-11-9 13:11:05 >
# 3 Re: Window freezing when drawing rectangles repeatedly
This is likely the case that WM_PAINT is a low priority message. You could try forcing a window update with the following function: UpdateWindow() ( http://msdn.microsoft.com/library/en-us/gdi/pantdraw_4zef.asp)
JasonD at 2007-11-9 13:12:04 >