AddWindowTimer()

Syntax

AddWindowTimer(#Window, Timer, Timeout)
Description
Adds a new timer to the specified window. This will cause #PB_Event_Timer events to be received periodically in the WindowEvent() or WaitWindowEvent() functions. The RemoveWindowTimer() function can be used to remove the timer again.

Parameters

#Window The window to use. A timer is always attached to a window and will be removed if that window is closed.
Timer An user-defined number that identifies this timer. Timers on separate windows may have overlapping numbers. This value will later be returned from EventTimer() when a #PB_Event_Timer is received. It can also be used to remove the timer again with the RemoveWindowTimer() function.
Timeout Specifies the amount of time (in milliseconds) between each #PB_Event_Timer events. The timer events will only be generated when there are no other events to be processed (timers are low-priority events). This means that the time that elapses between two timer events may be larger than the specified Timeout value. Timers are therefore not suited for precise timing but are rather intended to perform periodic tasks such as updating a gadget content or similar.

Return value

None.

Example

  If OpenWindow(0, 0, 0, 400, 100, "Timer Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ProgressBarGadget(0, 10, 10, 380, 20, 0, 100)
    AddWindowTimer(0, 123, 250)
    
    Value = 0
    Repeat
      Event = WaitWindowEvent()
      
      If Event = #PB_Event_Timer And EventTimer() = 123
        Value = (Value + 5) % 100
        SetGadgetState(0, Value)
      EndIf    
      
    Until Event = #PB_Event_CloseWindow
  EndIf

Remarks

To change the timer duration you have to remove the timer first, then add the same timer with a new 'Timeout' value again:
    RemoveWindowTimer(#Window, Timer)
    AddWindowTimer(#Window, Timer, Timeout)

See Also

RemoveWindowTimer(), EventTimer()

Supported OS

All

<- AddKeyboardShortcut() - Window Index - BindEvent() ->