问题
How can I change the tray icon to my.ico from within an Autohotkey script for example when the script is paused. For this I have come up with my own Pause Script menu item in the tray menu.
#SingleInstance ignore
Menu, Tray, Tip, AutoCase 0.11
Menu, Tray, Icon,,,1
Menu, Tray, Icon, D:\\Utilities\\AutoCase\\AutoCase-Icon-32x32.ico,1,1
Menu, Tray, Icon, D:\Utilities\AutoCase\AutoCase-Icon-(Paused)-32x32.ico,2,1
Menu, Tray, NoStandard
Menu, Tray, Add, &Pause Script, PauseHandler
Menu, Tray, Add, E&xit, ExitHandler
Menu, Tray, Default, &Pause Script
PauseHandler:
Menu, Tray, ToggleCheck, &Pause Script
MsgBox %A_IsPaused%
if A_IsPaused=1
{
Pause Off
Menu, Tray, Icon,,1,1
}
else ; <>1
{
Menu, Tray, Icon,,2,1
Pause On
}
return
ExitHandler:
ExitApp
return
When compiling the script, I face with an error warning that the icon file cannot be loaded. Please advise in this regard.
回答1:
You should use your second option without quotes:
Menu, Tray, Icon, D:\Utilities\AutoCase\AutoCase-Icon-(Paused)-32x32.ico, 2, 1
回答2:
Menu, Tray, Icon, %A_WorkingDir%\icon\AutoCase-Icon-32x32.ico,,1
Above loads the icon from folder Icon in the working directory of the script. Ensure that the path use single backslash (\) and is without quotation marks ("").
Thanks to MCL and then Elliot Denolf for their contributions.
来源:https://stackoverflow.com/questions/21967404/change-autohotkey-tray-icon-from-within-script