The code by gnozal does the exact same thing that WindowEvent() does.
(except for the delay, and WindowEvent() handles shortcuts too)
It is recommended to call WindowEvent() in a loop until it returns 0.
This way you make sure all redraw events get processed as quickly as possible.
the code by gnozal does process only one event per DoEvents() call, which, depending
on what you do between those calls can still lead to an unresponsive gui.
Also the Delay(1) is not a good choise. As long as your program is still working on something
in a loop, it makes no sense to slow that down with a delay.
The Delay makes only sense where your app has actually nothing to do at the moment
and you want to avoid using 100% cpu.)
Short Version:
Code: Select all
Procedure DoEvents()
While WindowEvent(): Wend
EndProcedure
This makes sure any waiting events are processed, so the gui is redrawn correctly.
However, you must notice that this discards any user events like button clicks and such
too. So i suggest before entering the loop you are in to use DisableGadget() to disable
any buttons, so tha user knows that clicking them has no effect, and enable them again
when entering the main loop again.
Otherwise the user might wonder why your program is not reacting to his input.
If you have lets say an "Abort" button that can stop what you are currently doing,
or any other event you need to check, i recommend this:
Code: Select all
Procedure DoEvents()
Repeat
event = WindowEvent()
; check for the abort condition here, for example a #PB_Event_Gadget on a button
; and set a global variable that will abort the loop
Until event = 0 ; stop processing when all waiting events are done
EndProcedure
these 2 ways are both 100% crossplatform compatible btw.
It is also recommended to tell the user in some way that your app is busy, especially
if what you are doing takes a little time. This can be done by opening a small "busy"
window, or putting a "processing, please wait..." in the statusbar.
Also a progressbar is always a good choise.
If you don't do that, the user will think that the app hangs if he doesn't know why it is
not responding for some time and believe your app is not well coded.
.. and you don't want that, do you?
hope that helps a bit...