Greetings.

Below, I have copied a section of code I am using to draw numerous square shaped regions
into a GUI window. The DO Loop runs through all the squares to
be drawn in the window (a process repeated through sequential configurations of squares),
and the Windows API statements are used to do the actual drawing in the window.

This is an extremely SLOW process, as is evident when I increase the redraw rate.
Any faster than a 500 ms redraw rate causes the routine to crash.

I would truly appreciate any help in understanding why this code is so SLOW, when, for example,
apparently simple cell phone games have such apparently FAST graphics response and redraw rates.....

Clearly, I'm not getting something essential, but I can't quite figure out what it is.


DO I=1, NUMBER_OF_AGENTS

x1 = AGENT_GRAPHIC(I)%X*200
y1 = -(AGENT_GRAPHIC(I)%Y*200)
x2 = x1 + 200
y2 = y1 - 200
COLOR = AGENT_GRAPHIC(I)%COLOR

Brush = CreateSolidBrush(color)
oldBrush = SelectObject(dc, Brush)
result = Rectangle(dc, x1, y1, x2, y2)
result = SelectObject(dc, oldBrush)
result = DeleteObject(Brush)

ENDDO