I know, this is an old issue which was discussed some years ago in hundreds of threads. Nevertheless I can't find the 'final' method.
I know how to change the tray icon by a direct command, e.g.:
Code: Select all
If A_IsSuspended ; change the 'Suspended' icon
Menu, Tray, Icon, %IcoS%, , 1
I wasn't able to adapt an old solution using OnMessage/WM_COMMAND presented by Lexikos (https://autohotkey.com/board/topic/2451 ... tray-icon/) to an up-to-date solution (see below*)...
Thank you very much in advance!
* This doesn't work reliably:
Code: Select all
;;;
; Change tray icons:
Menu, Tray, Icon, %IcoN%, , 1
OnMessage(0x111, "WM_COMMAND")
;;;
RETURN
WM_COMMAND(wP)
{
Global IcoN, IcoP, IcoS
Static IsPaused, IsSuspended
Critical
SetFormat, Integer, D ; to be sure (since if..in compares alphabetically)
id := wP & 0xFFFF
If id in 65305, 65404, 65306, 65403
{
If id in 65306, 65403
IsPaused := !IsPaused
Else
IsSuspended := !A_IsSuspended
If IsSuspended
{
Menu, Tray, Icon, %IcoS%, , 1
Return
}
If IsPaused
{
Menu, Tray, Icon, %IcoP%, , 1
Return
}
If !IsSuspended && !IsPaused
Menu, Tray, Icon, %IcoN%, , 1
}
}
; https://autohotkey.com/board/topic/24515-how-to-change-the-tray-icon/
; Note: IsPaused will go out of sync if the "Pause" command is used from script, unless you also call WM_COMMAND(65306,0).
; Update (July 15, 2009): As of v1.0.48, you may use the built-in variable A_IsPaused.