Change the tray icon – up-to-date method?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Change the tray icon – up-to-date method?

16 Jul 2018, 09:30

Hi!

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
But how to achieve in a script that all three tray icons (normal, suspended, paused) are replaced by custom icons without such direct commands?

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.
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: Change the tray icon – up-to-date method?

17 Jul 2018, 00:47

No helping tips? Is my question too trivial?
User avatar
jmeneses
Posts: 524
Joined: 28 Oct 2014, 11:09
Location: Catalan Republic

Re: Change the tray icon – up-to-date method?

17 Jul 2018, 03:28

Hello newbieforever
Try this

Code: Select all

#NoEnv 
#SingleInstance force 
#Persistent   

IcoN := "C:\Temp\iconN.ico"    ;Status Normal
IcoP := "C:\Temp\iconP.ico"    ;Script Paused
IcoS := "C:\Temp\iconS.ico"    ;Script Suspended
IcoT :=	"C:\Temp\iconT.ico"    ;Script Paused + Suspended
	
Menu, Tray, Icon, % IcoN, , 1
OnMessage(0x111, "WM_COMMAND")
RETURN

WM_COMMAND(wP){
  Global IcoN, IcoP, IcoS, IcoT
  Critical
  SetFormat, Integer, D ; to be sure (since if..in compares alphabetically)
  If !( (id := wP & 0xFFFF) ~= 65305 "|" 65306) {
     Return
  }
  If (id = 65305)   ;Script SUSPENDED
  	  iConTray := ( (!A_IsSuspended && A_IsPaused) ? IcoT : !A_IsSuspended ? IcoS : A_IsPaused ? IcoP : IcoN)
  If (id = 65306)   ;Scritp PAUSED
    	iConTray := ( (!A_IsPaused && A_IsSuspended) ? IcoT : !A_IsPaused ? IcoP : A_IsSuspended ? IcoS : IcoN)
   Menu, Tray, Icon, % IconTray
}

Donec Perficiam
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Change the tray icon – up-to-date method?

17 Jul 2018, 04:01

- This script tries to change the icons in the address space:
change AutoHotkey's 4 systray icons - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=46043
- I also added this to my wish list, 'tray icons: specify hIcons for the 4 icons':
Wish List 2.0 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 13&t=36789
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: Change the tray icon – up-to-date method?

17 Jul 2018, 14:00

@jmeneses: Fantastic, exactly what I wanted, works perfectly. Thank you very much!

@jeeswg: Very interesting, I will study your method.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee and 243 guests