Jump to content


Photo

how to assign tray icon in AutoHotkey_L?


  • Please log in to reply
5 replies to this topic

#1 Onesimus Prime

Onesimus Prime
  • Members
  • 10 posts

Posted 15 June 2010 - 11:55 AM

I was using ladiko's Compile_AHK.exe to compile a script "normally," and assigning the "main icon" also took care of the tray icon. Then I switched to the .bin from AutoHotkey_Lw, and the tray icon is suddenly the haphazard green H. I then tried
Menu, Tray, Icon,, %A_ScriptFullPath%, 1
(and a few other permutations) to assign that self-same "main icon" as the tray icon, but it doesn't seem to work.

How in the world do I assign an icon embedded in a compiled .exe as the tray icon when using AutoHotkey_Lw?

Thanks!


P.S. An example given in the "L" documentation is incorrect, I believe: isn't
Menu, Icon, MenuItemName, Filename.png,, 0
missing the "MenuName" element?

#2 a4u

a4u
  • Guests

Posted 15 June 2010 - 01:18 PM

Not sure if I understand your dilema here, but the following works for me:
Menu, Tray, Icon, [color=red]<Path>[/color],, 0
Or, you can set the tray icon using Ahk2Exe.exe to compile. Finally, if you use a Resource Hacker, you can change the icons in AutoHotkeySC.bin file.

#3 Lexikos

Lexikos
  • Administrators
  • 8850 posts

Posted 15 June 2010 - 01:31 PM

AutoHotkey_L uses a separate icon resource for the tray icon since it would otherwise end up with the large icon scaled down, which looks very poor. If the compiled script detects that Ahk2Exe has customized the main icon, it uses that instead of the separate tray icon resource. However, since Compile_AHK II replaces the icon resource directly, the compiled script cannot detect that the icon has been replaced and therefore continues to use the separate tray icon resource.

SeedSeifer brought this issue up a while back. That post wasn't very clear, but the posts following it shed more light on the issue.

Anyway, your workaround should work if you remove the extra comma.

An example given in the "L" documentation is incorrect,

I've corrected it. Thanks.

Finally, if you use a Resource Hacker, you can change the icons in AutoHotkeySC.bin file.

Right - icon group 230 contains the tray icon.

#4 Onesimus Prime

Onesimus Prime
  • Members
  • 10 posts

Posted 21 June 2010 - 02:46 AM

Re: the extra comma - I was trying to leave a space for "MenuItemName"--this isn't necessary?

I was trying to use
Menu, Tray, Icon, %A_ScriptFullPath%,159,5
I used %A_ScriptFullPath% because the icon is supposed to be in the compiled .exe. I compiled the .exe without the above Menu line and found out via ResHacker that my icon was in Group 159 and the 16-pixel version was "Ordinal name: 5". But when I compile it with that Menu line and try to run the .exe, it complains:
---------------------------
Error: Can't load icon. The current thread will exit.
...
Line#
---> 024: Menu,Tray,Icon,%A_ScriptFullPath%,159,5
---------------------------
And of course I can't actually check it before compiling, as the icon is not yet contained in the script file... Any suggestions on how to fix that troublesome line?

[and just for kicks, I did also try it with the extra comma: Menu, Tray, Icon,, %A_ScriptFullPath%,159,5 - the compiled program at least runs without the error, but the tray icon is still wrong.]

Thanks!

#5 Lexikos

Lexikos
  • Administrators
  • 8850 posts

Posted 22 August 2010 - 01:02 PM

Apologies for the very late reply; I wasn't watching the topic. Have you sorted it out yet?

Re: the extra comma - I was trying to leave a space for "MenuItemName"--this isn't necessary?

It is necessary to not have the extra comma unless you want to set the icon of a menu item in the tray menu. Note the difference in usage:

Menu, MenuName, Icon, MenuItemName, FileName [, IconNumber, IconWidth]
Menu, Tray, Icon [, FileName, IconNumber, 1]

Menu, Tray, Icon, %A_ScriptFullPath%,159,5

As I already mentioned, the code in your first post was correct aside from the extra comma.

However, your usage of IconNumber in the code above is incorrect. It should be either 1 or -159.

To use an icon group other than the first one in the file, specify its number for IconNumber (if omitted, it defaults to 1). For example, 2 would load the default icon from the second icon group.
Source: Menu

Negative icon numbers may be used to identify a group icon resource within an executable file. For example, the following sets the tray icon to the default icon used by ahk files:

Menu, Tray, Icon, %A_AhkPath%, -160
Source: AutoHotkey_L Features

Why did you think the "ordinal number" should be used anywhere? The correct usage of that parameter is:

Specify 1 for the last parameter to freeze the icon, or 0 to unfreeze it (or leave it blank to keep the frozen/unfrozen state unchanged).
Source: Menu



#6 MilesAhead

MilesAhead
  • Members
  • 429 posts

Posted 14 July 2011 - 09:47 PM

I've been updating to AutoHotkey_L to get with some of the Windows Seven stuff. I'm just wondering if it's still at the state where one needs the Menu Tray Icon work-around to avoid the green H?

Or maybe I have to reinstall Scite4AHK beta?