ChangeSysTrayIcon()

Syntax

ChangeSysTrayIcon(#SysTrayIcon, ImageID)
Description
Changes the specified icon in the SysTray area.

Parameters

#SysTrayIcon The systray icon to change.
ImageID The new image to use for the systray icon. It is advised to use a PNG image in order to have a transparency layer. ImageID() may be used to get this ID easily.

Return value

None.

Example

  If OpenWindow(0, 0, 0, 300, 100, "", #PB_Window_Invisible)
    ; Create an image with a yellow box to be used for the Systray icon:
    If CreateImage(0, 16, 16) And StartDrawing(ImageOutput(0))
      Box(0, 0, 16 , 16, $00DDDD)
      StopDrawing()
    EndIf
    AddSysTrayIcon(0, WindowID(0), ImageID(0))
    ; Create a pop-up menu to be used with the Systray icon later:
    If CreatePopupImageMenu(0)
      MenuItem(0, "Exit")
    EndIf
    
    AddWindowTimer(0, 0, 1000) ; Add a window timer, which should cause a change of the Systray icon after every 1000 ms
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_Timer
          ; Update the Systray icon image with a randomly sized red circle on the yellow background
          If StartDrawing(ImageOutput(0))
            Box(0, 0, 16 , 16, $00DDDD)
            Radius = Random(6, 2)
            Circle(8, 8, Radius, $0000DD)
            StopDrawing()
            ChangeSysTrayIcon(0, ImageID(0))
          EndIf
        Case #PB_Event_SysTray
          Select EventType()
            Case #PB_EventType_RightClick, #PB_EventType_LeftClick
              DisplayPopupMenu(0, WindowID(0)) ; Show pop-up menu after a mouse-click on the Systray icon
          EndSelect
        Case #PB_Event_Menu
          Select EventMenu()
            Case 0 ; Quit after clicking on the 'Exit' menu item associated to the Systray icon
              RemoveSysTrayIcon(0)
              FreeMenu(0)
              CloseWindow(0)
              End
          EndSelect
      EndSelect
    ForEver
  EndIf

See Also

AddSysTrayIcon()

Supported OS

All

<- AddSysTrayIcon() - SysTray Index - IsSysTrayIcon() ->