Menu icon error Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Ecimeric
Posts: 130
Joined: 11 Jan 2017, 02:23

Menu icon error

12 Apr 2021, 17:19

Code: Select all

;@Ahk2Exe-SetMainIcon Icons\Icon1.ico
;@Ahk2Exe-AddResource Icons\Icon2.ico

Menu, MyMenu, Add, MenuItemName
Menu, MyMenu, Icon, MenuItemName, Icon2.ico
Menu, MyMenu, Show
ExitApp

MenuItemName:
Why am I getting a Can't load icon error for the menu icon? (Both icons are added to the compiled executable, and the main icon appears as expected.)
User avatar
boiler
Posts: 16933
Joined: 21 Dec 2014, 02:44

Re: Menu icon error

12 Apr 2021, 17:22

You put it in a folder inside the script directory named Icons, so you need to change the line where you load it to the following:

Code: Select all

Menu, MyMenu, Icon, MenuItemName, Icons\Icon2.ico
Ecimeric
Posts: 130
Joined: 11 Jan 2017, 02:23

Re: Menu icon error

12 Apr 2021, 17:51

Shouldn't the script be looking for the icon in the compiled executable; otherwise, why would I add it as a resource?
User avatar
boiler
Posts: 16933
Joined: 21 Dec 2014, 02:44

Re: Menu icon error

12 Apr 2021, 18:14

It looks for it where you tell it to look for it. The script can also run when it’s not compiled into an exe, and you have to tell it where it is located. Once it’s compiled, it’s still looking for it in that location. Scripts don’t look inside the compiled executable. The script isn’t even doing that for the main icon. You accomplished that via a compiler directive (which could have been accomplished script commands including FileInstall instead). Your compiler directive for the menu icon only says to load it in a certain location (which also could have been done via FileInstall), not to implement it as a menu icon or even to inform the script it exists in the executable.
teadrinker
Posts: 4327
Joined: 29 Mar 2015, 09:41
Contact:

Re: Menu icon error

12 Apr 2021, 18:23

You need to specify the resorce name in this case (14 (RT_GROUP_ICON): .ico).
Should be like this:

Code: Select all

;@Ahk2Exe-SetMainIcon Icons\Icon1.ico
;@Ahk2Exe-AddResource Icons\Icon2.ico, 14

Menu, MyMenu, Add, MenuItemName, Dummy
if A_IsCompiled
   Menu, MyMenu, Icon, MenuItemName, % A_ScriptFullPath, 2
else
   Menu, MyMenu, Icon, MenuItemName, Icons\Icon2.ico
Menu, MyMenu, Show

Dummy() {
   
}
User avatar
boiler
Posts: 16933
Joined: 21 Dec 2014, 02:44

Re: Menu icon error

12 Apr 2021, 18:30

Thanks, @teadrinker. I should have looked up how that works. :?
teadrinker
Posts: 4327
Joined: 29 Mar 2015, 09:41
Contact:

Re: Menu icon error  Topic is solved

12 Apr 2021, 18:44

No, it turns, this was not completely true. :)
;@Ahk2Exe-SetMainIcon replaces the first standart icon, to replace the second, you need to specify the name 160. So, should be:

Code: Select all

;@Ahk2Exe-SetMainIcon Icons\Icon1.ico
;@Ahk2Exe-AddResource Icons\Icon2.ico, 160

Menu, MyMenu, Add, MenuItemName, Dummy
if A_IsCompiled
   Menu, MyMenu, Icon, MenuItemName, % A_ScriptFullPath, 2
else
   Menu, MyMenu, Icon, MenuItemName, Icons\Icon2.ico
Menu, MyMenu, Show

Dummy() {
   
}
or

Code: Select all

;@Ahk2Exe-SetMainIcon Icons\Icon1.ico
;@Ahk2Exe-AddResource Icons\Icon2.ico

Menu, MyMenu, Add, MenuItemName, Dummy
if A_IsCompiled
   Menu, MyMenu, Icon, MenuItemName, % A_ScriptFullPath, 6
else
   Menu, MyMenu, Icon, MenuItemName, Icons\Icon2.ico
Menu, MyMenu, Show

Dummy() {
   
}
Ecimeric
Posts: 130
Joined: 11 Jan 2017, 02:23

Re: Menu icon error

12 Apr 2021, 18:57

teadrinker wrote:
12 Apr 2021, 18:44

Code: Select all

   Menu, MyMenu, Icon, MenuItemName, % A_ScriptFullPath, 6
Thank you; how did you know to use 6 when there are only two icons in the compiled executable?
teadrinker
Posts: 4327
Joined: 29 Mar 2015, 09:41
Contact:

Re: Menu icon error

12 Apr 2021, 19:13

No, if you don't specify any icons, the icon resource in the compiled file looks like this:
 
 Image
 
There are all icons from AutoHotkey.exe, 5 items. So, if you add an icon without a name, it becomes 6th.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Joey5 and 95 guests