Refresh window in a loop ?

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by plopzz.

Hi

I have a loop who can take 10s to some minutes
I want to display the state in a text gadget but while the loop, window are freezed... How i can refresh the window when i display the text ? like form.refresh in delphi ?

Thanks
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

The window is only updated, if WindowEvent() or WaitWindowEvent() is called.
So you have to put WindowEvent() in you loop. (and better check if it returns
simething like #PB_EventCloseWindow and take the right action then).

Timo

http://freak.coolfreepages.com/
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by plopzz.

WindowEvent() are ok for my task

thanks :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Denis.

Hi plopzz,

try with this : UpdateWindow_(WindowId(#yourWindowIDConstant))
witch #yourWindowIDConstant is your Window (to refresh) ID constant

Inside a loop, it will slow down your app.

Denis

Bonne journée.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

UpdateWindow_() causes Windows to update the window (redraw everything) BUT, for the stuff to be actually
redrawn, the Program must process the redraw messages, which is what WindowEvent() does.

I don't think UpdateWindow_() is needed here, as there will be automatically a redraw event, if you change
the TextGadget.

Timo

http://freak.coolfreepages.com/
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Denis.

Hi Freak, i think your right


Denis

Bonne journée.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by CONVERT.
Originally posted by plopzz

WindowEvent() are ok for my task

thanks :)
Do not forget to write a delay(1) after the WindowEvent().

To see the difference with or without delay(1), run in the same time the monitoring of the processor (Windows tool). The consumption of processor is great without delay(1), and very few with delay(1).

Jean, France.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

Hmm, no I wouldn't do that.
You are right, that a loop with WindowEvent() and no Delay inbetween takes all CPU Time (as the System can't go idle in that
case), but is I understand plopzz, he has a loop that needs to calculate/do stuff fast, and he only want's to refresh the
window in that time.
So a delay in that loop would really slow it down a lot, and that is not a good thing. I think it is perfectly legal for a
programm to take all CPU speed, if it really needs to do stuff fast. Only, if a program doesn't do much (wait for user input for
example, the Delay(1) should be put in, or WaitWindowEvent() used.

btw: WindowEvent() was ddesigned to be used in such loops.

Timo

http://freak.coolfreepages.com/
Post Reply