AddWindowTimer()

语法

AddWindowTimer(#Window, Timer, Timeout)
概要
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.

参数

#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.

返回值

无.

示例

  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

参阅

RemoveWindowTimer(), EventTimer()

已支持操作系统

所有

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