TrayIcon_Update() { global IconsDir, AppName static currentId, currentIcon, currentMessage If _start Is Integer { If (_start > 0) _start -= 1 } Else _start := 0 Len := TrayIcon_Queue("len") - _start If Len Is Integer { _TopPri := 0 Loop %Len% { _Index := A_Index + _start _Item := TrayIcon_Queue(_Index) _Timeout := SA_Get(Item, 4) If (_Timeout >= A_TickCount) { _Remove := SA_Set(_Remove, _Index) } Else { _Pri := SA_Get(_Item, 3) If _Pri Is Not Integer _Pri := 1 If (_Pri >= _TopPri) { _TopPri := _Pri _TopIndex := _Index } } } If (_TopIndex) and (_TopIndex != currentId) { _Item := TrayIcon_Queue(_TopIndex) _Type := SA_Get(_Item, 1) If _Type _Type := "_" . _Type _Icon = %AppName%%_Type%.ico If (_Icon != currentIcon) { Menu, Tray, Icon, %IconsDir%\%_Icon% currentIcon := _Icon } _Message := SA_Get(_Item, 2) If (_Message != currentMessage) { Menu, Tray, Tip, %_Message% currentMessage := _Message } } Else _Result := 0 If _Remove { Loop,% SA_Len(_Remove) { _Index := SA_Get(_Remove, A_Index) TrayIcon_Unset(_Index) } } } Else _Result := false Return _Result } TrayIcon_Alert(_type="", _message="", _function="", _priority="", _timeout="") { If Not _type _type="Alert" If Not _message _message="There is an alert" _message .= " (Double-click to display)" If _priority Is Not Integer _priority := 75 If _timeout Is Integer { _timeout := _timeout * 1000 _timeout := A_TickCount+_timeout } Else _timeout := "" ; Once it's clicked: __expr(_function) } TrayIcon_Set(_type="", _message="", _priority="", _timeout="") { If Not _type _type := "Processing" If Not _message _message := "Working..." If _priority Is Not Integer _priority := 50 If _timeout Is Integer { _timeout := _timeout * 1000 _timeout := A_TickCount + _timeout } Else _timeout := "" NewArr := SA_Set(NewArr, _type) NewArr := SA_Set(NewArr, _message) NewArr := SA_Set(NewArr, _priority) NewArr := SA_Set(NewArr, _timeout) actionId := TrayIcon_Queue("add", NewArr) Return actionId } TrayIcon_Unset(_actionId) { Return TrayIcon_Queue("del", _actionId) } TrayIcon_Queue(_Action="", _value="") { static Queue If _Action = "" _Action = "last" If _Action { If _Action Is Integer { _Result := SA_Get(Queue, _Action) } Else If (_Action = "length" or _Action = "len") { _Result := SA_Len(Queue) } Else If (_Action = "last") { _Result := SA_Get(Queue, "-1") } Else If (_Action = "add") { _Result := SA_Set(Queue, _value) } Else If (_Action = "del") { _Result := SA_Del(Queue, _value) } Else _Result := false } Else _Result := false }