TraySetIcon with AHK V2?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Ashtefere
Posts: 14
Joined: 02 Dec 2017, 11:14

TraySetIcon with AHK V2?

18 Jan 2018, 03:21

Cant seem to get this to work.
I have this at the top of the script:

Code: Select all

TraySetIcon(A_WorkingDir . "trayicon.ico")
And I get "call to nonexistent function".

What am I doing wrong?
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: TraySetIcon with AHK V2?

18 Jan 2018, 03:31

Did you download AHK v2? :arrow: v2 (Downloads -> Current Alpha Release)
The function is not available in AHK v1.

Cheers.
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: TraySetIcon with AHK V2?

18 Jan 2018, 11:51

Following up on Helgef's comment, if you want to set the tray icon in V1, here's how:

Code: Select all

TrayIcon:=A_WorkingDir . "\trayicon.ico"
Menu,Tray,Icon,%TrayIcon%
Btw, note the backslash before the icon's file name, because A_WorkingDir does not have an ending backslash. Also, if you'd like to set a tray tip in V1:

Code: Select all

TrayTip:="whatever tray tip you want"
Menu,Tray,Tip,%TrayTip%
Regards, Joe
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: TraySetIcon with AHK V2?

18 Jan 2018, 13:04

I found the missing AHK v1 function.

Code: Select all

TraySetIcon(FileName:="", IconNumber:="", Freeze:="")
{
    Menu Tray, Icon, %FileName%, %IconNumber%, %Freeze%
}
It's quite a new function in AHK v2, so you may need to get the latest version.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Ashtefere
Posts: 14
Joined: 02 Dec 2017, 11:14

Re: TraySetIcon with AHK V2?

19 Jan 2018, 01:10

Yeah, already using the very latest alpha of v2.
Ashtefere
Posts: 14
Joined: 02 Dec 2017, 11:14

Re: TraySetIcon with AHK V2?

19 Jan 2018, 01:12

JoeWinograd wrote: Btw, note the backslash before the icon's file name, because A_WorkingDir does not have an ending backslash. Also, if you'd like to set a tray tip in V1:
Regards, Joe
That was it! Thanks!
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: TraySetIcon with AHK V2?

19 Jan 2018, 03:22

You're welcome. I'm glad that was it and that it's now working, but I find it strange that a non-existent icon file (which is, in essence, what it becomes without the backslash) would result in "call to nonexistent function". I would expect a "file not found" or "cannot load icon" type of error — that's what V1 does:
icon file bad.gif
icon file bad.gif (9.85 KiB) Viewed 2310 times
Regards, Joe
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: TraySetIcon with AHK V2?

19 Jan 2018, 04:08

Good catch about the \ JoeWinograd, and indeed, it wouldn't cause a call to nonexistent function error, there must have been two problems.

Cheers.
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: TraySetIcon with AHK V2?

19 Jan 2018, 10:56

Helgef wrote:there must have been two problems
Good point, Helgef. So, question for Ashtefere: Did you change anything besides adding the backslash? If not, then V2 is handling that error in a weird way. Regards, Joe

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: V4Friend and 36 guests