Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Tutorial: How to compile .AHK files include your own icons


  • Please log in to reply
8 replies to this topic
deleyd
  • Members
  • 64 posts
  • Last active: Sep 27 2011 06:35 AM
  • Joined: 08 Mar 2008
I recently released my BatteryDeley laptop low battery alert and had a bit of figuring out how to get my own icons into the compiled .exe file. While I still remember how, I'm writing it down here for others.

Update (March 2011): The new AutoHotkey requires an addition to the code to set the tray icon:
;set tray icon
if A_IsCompiled
  Menu, Tray, Icon, %A_ScriptFullPath%, -159

Pre-Lesson Preparation[*:xku7l9ez]Install Compile_AHK_II[*:xku7l9ez]Download program Compile_AHK II and install.
Download from:
<!-- m -->https://ahknet.autoh... ... _Setup.exe<!-- m -->
The related forum post is: Compile_AHK II - for those who compile!
<!-- m -->http://www.autohotke...pic.php?t=22975<!-- m -->[*:xku7l9ez]Download the testicons.zip and extract the files.
<!-- m -->http://www.daviddele... ... ticons.zip<!-- m -->[/list]

Lesson 1: The Default Icons
[*:xku7l9ez]Right-click on TestIcons.ahk, select "Compile with options"

[*:xku7l9ez]Select the 'Icons' tab
(If the text is German, and you're not fluent in German, select the 'Sprache' combo box on the far right of the tabs and choose "en-us")

Posted Image

You get 7 icons. Leave them all blank for now.

[*:xku7l9ez]Click 'Compile' (lower left)

[*:xku7l9ez]Find and run your resulting TestIcons.exe program.
Notice the AutoHotkey 'H' icon in the system tray. Right-click it and select 'About'

Posted Image

These are the 7 default icons you get (notice there is no Icon8):

Posted Image

Lesson 2: Add Our Own Icon

Update (March 2011): The new AutoHotkey requires an addition to the code to set the tray icon:
;set tray icon
if A_IsCompiled
  Menu, Tray, Icon, %A_ScriptFullPath%, -159
Recompile and this time add our own icon.
[*:xku7l9ez]Right-click on TestIcons.ahk and select "Compile with options"
[*:xku7l9ez]Select the 'Icons' tab
[*:xku7l9ez]Check the box for the first one and select file battery_16x16.ico

Posted Image

[*:xku7l9ez]Click 'Compile' (lower left)
[*:xku7l9ez]Find and run your resulting TestIcons.exe program.
Notice the battery icon in the system tray. Right-click it and select 'About'

Posted Image

Posted Image

Lesson 3: Creating a Multiple-Icon .ICO file

It's possible for an .ICO file to have different sizes of (usually) the same icon.
For example, an ICO icon file can have a 16x16 image and also a 32x32 image.

To create a .ICO file with both a 16x16 image and also a 32x32 image:

[*:xku7l9ez]Download & install the free program Icon Sushi
<!-- m -->http://www.towofu.net/soft/e-aicon.php<!-- m -->
[*:xku7l9ez]load file battery_16x16.ico
[*:xku7l9ez]load file battery_32x32.ico
[*:xku7l9ez]select both,

Posted Image

[*:xku7l9ez]FILE -> SAVE AS MULTIPLE ICON
save it as battery16+32.icoWe can check our new icon file by loading it into IrfanView
and clicking the Previous Page / Next Page buttons:

Posted Image

Posted Image



Lesson 4: Add Our Own Multiple-Icon .ICO file

Recompile and this time add the new icon we just created.
[*:xku7l9ez]Right-click on TestIcons.ahk, select "Compile with options"
[*:xku7l9ez]Select the 'Icons' tab
[*:xku7l9ez]Check the box for the first one and select battery16+32.ico (the .ico file we just created in the previous step)

Posted Image

[*:xku7l9ez]Click 'Compile' (lower left)
[*:xku7l9ez]Find and run your resulting TestIcons.exe program.

http://www.daviddele...testicons11.gif

Notice the small 16x16 size icon is used for the system tray, while the larger 32x32 size icon is used where 32x32 size is needed. Both are in battery16+32.ico. Which one gets used depends on what size is needed.
Lesson 5: Add A Duck Icon

Recompile and this time add both the new icon we just created and the duck icon.
[*:xku7l9ez]Right-click on TestIcons.ahk, select "Compile with options"
[*:xku7l9ez]Select the 'Icons' tab
[*:xku7l9ez]Check the box for the first one and select battery16+32.ico
[*:xku7l9ez]Check the box for the second one and select duck.ico

http://www.daviddele...testicons12.gif

[*:xku7l9ez]Recompile and run

http://www.daviddele...testicons13.gif

Epilogue

And now you can check the TestIcons.ahk source code to see how the icons are accessed.


—David Deley
<!-- m -->http://www.daviddeley.com<!-- m -->

BoBo³
  • Guests
  • Last active:
  • Joined: --
@ deleyd
what about to move that HowTo into Scripts & Functions (which is more that kind of archive for 'finished' projects)?!
Or (like the incredible SKAN has done, with his WinSpector-HowTo) drop it at Utilities & Resources?!

Anyway, thx for sharing your time 8)

n-l-i-d
  • Guests
  • Last active:
  • Joined: --
Very nice tutorial! 8)

jaco0646
  • Moderators
  • 3165 posts
  • Last active: Apr 01 2014 01:46 AM
  • Joined: 07 Oct 2006
Well done! The more AHK tutorials like this we can get, the better. I've linked to this thread in the Wiki.

I think it's fine to keep it in the Help forum. It's still searchable, and the Help forum does say, "Post helpful tips and tricks." Perhaps if you PM'd ladiko, he would put a link at the beginning of his Compile_AHK thread, since this tutorial relates to it.

deleyd
  • Members
  • 64 posts
  • Last active: Sep 27 2011 06:35 AM
  • Joined: 08 Mar 2008
Maybe we need a Tutorials forum. I asked earlier where to put Tutorials and I get different answers from different people.

jaco0646
  • Moderators
  • 3165 posts
  • Last active: Apr 01 2014 01:46 AM
  • Joined: 07 Oct 2006
I wish there were enough Tutorials written to justify a forum. Until then, listing them in the Wiki and hosting them on the forum works fine (IMO it doesn't really matter which forum). The Wiki doesn't get enough traffic to be worth hosting anything there; and maybe I'm just used to it, but I like the format of the forum better anyway.

aobrien
  • Members
  • 77 posts
  • Last active: Mar 06 2014 04:42 AM
  • Joined: 14 Feb 2008
Excellent tutorial!

I'll be spending some quality time with it in the near future :)

bacon
  • Guests
  • Last active:
  • Joined: --
This deleted my original script when I compiled. Why in the world would you want that? Or am I missing something? Thank god I backed it up! :roll:

kArThIcK
  • Members
  • 142 posts
  • Last active: Aug 31 2017 03:40 AM
  • Joined: 13 May 2013

HI, happy.png

i've been searching for a way to add icons and other files into my script; and i found this post.

Good tutorial.wink.png

But i have a doub't.confused.png

there is a tab for "Resources", in which we can add our own files into the compiled script.

i tried adding a file in it. It compiles and compresses but doesn't include the custom files.

do u know why this happened or where i did a mistake?sad.png


This Is An Awesome Compilation Of Help Materials http://www.autohotkey.net/~faqbot/
;) :) B)