WindowEvent()

Syntax

Event = WindowEvent()
Description
Check if an event has occured on any of the opened windows.

WindowEvent() returns the next event from the event queue and returns zero when there are no more events. Unlike WaitWindowEvent() it doesn't wait for the next event - it always returns immediately.

This makes it useful for window event loops, where other processing needs to be done without waiting for an event to happen (e.g. Network transactions) and therefore WaitWindowEvent() can't be used.

It must be handled with care though if used on a continuing basis, because unlike WaitWindowEvent(), it will not give CPU time to other programs while waiting for an event and therefore consume all CPU power. In this case, either Delay() should be used somewhere in the loop or WaitWindowEvent() with a small timeout value.

To get the window number in which the event occurred, use the EventWindow() command.

Possible Events are :
  #PB_Event_Menu           : a menu has been selected
  #PB_Event_Gadget         : a gadget has been pushed
  #PB_Event_CloseWindow    : the window close gadget has been pushed
  #PB_Event_Repaint        : the window content has been destroyed and must be repained (useful for 2D graphics operations)
  #PB_Event_SizeWindow     : the window has been resized
  #PB_Event_MoveWindow     : the window has been moved
  #PB_Event_ActivateWindow : the window has been activated (got the focus)
A basic example for event handling can be found in the WaitWindowEvent() description.

Note: When opening a Window from a thread, the thread must also call WindowEvent() or WaitWindowEvent() in a loop to process events for this window, as window events are not sent between different threads.

The correct way to handle an WindowEvent() loop is something like that:
  Repeat 
    Event = WindowEvent() 

    If Event    ; An event was in the queue so process it 
      .... 
    Else  
      Delay(1)  ; No event, let the others apps get some CPU time too ! 
    EndIf 
  Until Event = #PB_Event_CloseWindow
Note: The 'Delay' shouldn't be put after each event, because when lot of events will come (like refresh, gadgets updates etc..) the app will wait 20 ms (on windows at least) between each event. So the delay need to be put when no events are received. Another way is to use WaitWindowEvent() with a small timeout value.

Supported OS

All

<- WaitWindowEvent() - Window Index - WindowHeight() ->