Page 1 of 1

Use Icons in compiled scripts

Posted: 16 Jan 2015, 06:15
by Peter2
I'm searching for the right workflow to do this:

I have:
- an AHK file
- usage of Icons like "Menu, Tray, Icon, Pdf.ico" and "SB_SetIcon("pdf16.ico",,1)"
- the needed ICO-files in the same folder
-> it works fine

I want to:
- compile the script
- use the "new" AHK2EXE (http://ahkscript.org/boards/viewtopic.php?f=24&t=521)
- embed the ICO into the EXE to get a single file

I need to now:
- how to integrate the ICO in the EXE. ICO is not yet supported by the compiler, but BMP and DIB. And DLL (??? never made it) and SCR (Scrennsaver?)
- how to call it from the AHK-code?

Thanks in advance

Re: Use Icons in compiled scripts

Posted: 16 Jan 2015, 07:32
by Guest
You can http://ahkscript.org/docs/commands/FileInstall.htm to include the icon in your exe so when the exe is run the ICO is extracted and you can use it.

Re: Use Icons in compiled scripts

Posted: 16 Jan 2015, 09:52
by Peter2
Thanks
Yes, "Fileinstall" is the perfect way for another idea and a 90%-perfect way for this topic (it works, but it creates files).

If someone can solve the other 10% (the real integration into the EXE) it would be great.

Re: Use Icons in compiled scripts

Posted: 16 Jan 2015, 10:13
by Flipeador
in my opinion 'FileInstall' works well, but is not exactly what I wanted. I think the issue is, how to use the files (.bmp, .png, etc.) included in the .exe file. and, moreover, will have to wait for a new update of the 'new' AHK2EXE.

Re: Use Icons in compiled scripts

Posted: 16 Jan 2015, 18:37
by MJs
if you want to get dirty with some work aroundsssssss, not one around
it's a stretch, but AHK has the ability to read icons from executable files, so why not itself also
so:
- read untill the end..
- compile your script as normal, with no InstallFile for the icons
- use reshacker, from the GUI or using CLI I prefer the latter (since you can do it all in one script and RunWait the commands one after another, nice workflow as far as I'm concern)
- add the icon to your EXE file (Icon group) (keep in mind the file already has the 8 AHK default icons, you can replace them or add your new icon at the end, either case pay attention to the icon number, either 1,2... or 9,10...)
- this is the first step I left it last, just to get the picture, Now the path to your icon is the path of your EXE which is A_ScriptFullPath
after all said and done this

Code: Select all

Menu, Tray, Icon, %A_ScriptFullPath%, 9
will change the tray icon to the icon you added using the ResHacker

I tried it and i worked fine for me, so afaik it should work nicely for you too
one more thing: thank you for making me think a little about that, since I had no use for it, I didn't think of it.
don't know about the new Ahk2Exe, hope it would simplify things for you

Re: Use Icons in compiled scripts

Posted: 17 Jan 2015, 13:46
by Peter2
At first I thought that the usage of Ressourcehacker is a lot of work which has to be repeated always when I compile the exe again, but the following process should work automated:

- Use the ;@AHK2Exe-Postexec directive
-- which calls a batch file
--- which contains command-line command for Ressourcehacker
---- which adds the Icons you created before.

I will see.

Peter

Re: Use Icons in compiled scripts

Posted: 17 Jan 2015, 14:34
by MJs
you don't need batch file, call the commands using runwait
the commands in the patch can be called directly
even the compilong process can be done from commend line without the GUI
when I'll have some time I may try and post the script once I'm done
it's simple, just go step by step. good luck

Re: Use Icons in compiled scripts

Posted: 17 Jan 2015, 14:40
by Peter2
MJs wrote:you don't need batch file, call the commands using runwait...
But using RunWait inside the code is not invoked after compiling. At first I have to compile, then I have to add the icon ... :think:

Re: Use Icons in compiled scripts

Posted: 17 Jan 2015, 14:49
by MJs
use another script, seperated, to compile using ahk2exe command line params, you'll find example in docs file, and then add icons using the commands from reshacker
but the key is your original script that has to have the numbers right like the icon 9 in my example
#persistant
Menu, Tray, Icon, %A_ScriptFullPath%, 9
use just these two line for testing

Re: Use Icons in compiled scripts

Posted: 17 Jan 2015, 15:26
by Peter2
MJs wrote:...and then add icons using the commands from reshacker...
Yes, that's exactly want I do with the batch which is started from the compiling program
MJs wrote:... but the key is your original script that has to have the numbers right like the icon 9 in my example...
Yes. I use numbers for names of the icongroups starting with 300, because the highest number (=name) of the AHK-compiler-icons is 230. (Of course other numbers or names are possible, but I decided for me to not disturb the original order)

Re: Use Icons in compiled scripts

Posted: 17 Jan 2015, 16:38
by MJs
ok, if that works and in your work flow then use it
is it solved then?

Re: Use Icons in compiled scripts

Posted: 17 Jan 2015, 16:40
by Peter2
MJs wrote:...is it solved then?
I would say: 99% yes. 1% would be the full integration into AHK2Exe.

Thanks and have a fine Sunday.

Re: Use Icons in compiled scripts

Posted: 17 Jan 2015, 16:56
by MJs
you too.
I hope you'll have that missing 1% soon.

Re: Use Icons in compiled scripts

Posted: 15 Jan 2023, 12:29
by wpb
Old post, I know, but...could you perhaps use a FileInstall command at a point in the program that is never reached? Then the compiler will add the file into the .exe, but it will never be extracted when the .exe is run. You can then get the icon data as described above. Haven't tested this idea, but it should work, I think.