Change autohotkey tray icon from within script

巧了我就是萌 提交于 2019-12-12 13:18:59

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!