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

The #Window parameter specifies the window for the timer. A timer is always attached to a window and will be removed if that window is closed.

The Timer parameter is a userdefined 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.

The Timeout parameter specifies the amount of time in milliseconds between the #PB_Event_Timer events.

Note: 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 ellapses 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.

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

Supported OS

All

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