Jump to content

Embedding resources into the .exe?


Recommended Posts

Are there any guides on how to embed resources, such as additional icons or sound files, into the compiled .exe? I've looked at the example in the compiler, but I lack context for nearly all of it.

Link to comment
Share on other sites

  • Moderators

Quinch,

SciTE4AutoIt3 Help <SciTE Help - Extra Utilities - AutoIt3Wrapper - Adding Extra Ico's to the program resources>. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

That's what I meant. It's all kind of gibberish to me {plus the example script doesn't seem to work even with fixed paths, might be system differences?} The #AutoIt3Wrapper_Res_Icon_Add or File lines seem self-explanatory enough, but how do I subsequently call on those resources?

For example, let's say I want to include cheese.ico, crepes.ico and abettermousetrap.ico as well as the Iamafish.mp3 in the executable, and then use TraySetIcon and SoundPlay to put them to use at an unspecified point in the script - how exactly do I refer to each of them?

Link to comment
Share on other sites

Call like this:

; First one will have number 3, then 4 ..etc
#AutoIt3Wrapper_Res_Icon_Add=.ResourcesIconAbort.ico ; number 3
#AutoIt3Wrapper_Res_Icon_Add=.ResourcesIconAbsent1.ico ; 4
#AutoIt3Wrapper_Res_Icon_Add=.ResourcesIconAbsent2.ico ; 5
;(...)

Regards,

João carlos.

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

  • Moderators

JScript,

No, the first added icon with #AutoIt3Wrapper_Res_Icon_Add will be indexed as -5.

Index 0 is the icon set by #AutoIt3Wrapper_Icon and -1 to -4 are filled by the default AutoIt tray icons.

Look carefully at the example in SciTE help. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Eh, no luck. Putting in a simple;

#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_Res_Icon_Add=Chat Baloon.ico
#AutoIt3Wrapper_Res_Icon_Add=Clapper.ico
#AutoIt3Wrapper_Res_Icon_Add=Clipboard.ico
For $x = 1 To 10
TraySetIcon(@ScriptFullPath, -$x)
Sleep(3000)
Next

Just cycles through the default AU3 icons and settles on the default one until the script finishes. Am I missing something obvious?

Link to comment
Share on other sites

  • Moderators

Quinch,

I take it you are compiling the script? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Aaannnnd there it is. I compiled with the standard "compile script" command - apparently the wrapper completely ignores the includes unless the "compile with options" option is used, so that's the catch.

So with that mystery solved, how do I refer to other types of included resources, like sounds in this case?

Edited by Quinch
Link to comment
Share on other sites

@Melba23

Then there were changes and I had not seen yet, because these sentence I pulled out my SciTE help:

;Add extra ICO files to the resources which can be used with TraySetIcon(@ScriptFullPath, 3) etc
; list of filename of the Ico files to be added, First one will have number 3, then 4 ..etc
; #AutoIt3Wrapper_Res_Icon_Add=Filename of ICO to be added.

Thanks for your information!

Regards,

João Carlos.

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

  • Moderators

Quinch,

When I run your code with my icons it works perfectly. :)

Are you sure that you are adding the icons? Can you check with ResHacker? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Quinch,

Sorry, missed that the first time round (although I now realise it was not there!). :)

M23

Edit: For sounds, look on the same SciTE Help page, but scroll down the icon code a bit to see Example 2. ;)

Edited by Melba23
Added sound advice

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Link to comment
Share on other sites

@Melba: Yeah, but again there's no explanation or context. The example goes

; Example 2
#AutoIt3Wrapper_Res_File_Add=C:WINDOWSMediatada.wav, SOUND, MYWAV
Global Const $SND_RESOURCE = 0x00040004
Global Const $SND_ASYNC = 1
DllCall("winmm.dll", "int", "PlaySound", "str", "MYWAV", "hwnd", 0, "int", $SND_RESOURCE)
DllCall("winmm.dll", "int", "PlaySound", "str", "MYWAV", "hwnd", 0, "int", BitOR($SND_RESOURCE, $SND_ASYNC))
For $n = 1 To 100
    Sleep(15)
    ToolTip("Asynch! " & $n)
Next

But other than the path to the file itself and some sort of dll call, none of this means anything to me, plus I'm inferring that I can't actually use these embedded files with the actual AutoIt functions. For a simpler solution, is it possible to embed the files on compile, then have the script extract them to a temp folder, call on them as needed and delete on exit?

Link to comment
Share on other sites

  • Moderators

Quinch,

there's no explanation or context

You have a working code example - how much more do you need? ;)

- 1. Use the directive to get the sound file into the exe resource table

- 2. Declare the 2 constants (or you could use the values directly)

- 3. Make the DllCall when you need the sound. Using ASYNC means your script continues as the sound plays - omitting it means the script pauses until the sound ends

Seems pretty simple to me. :)

If you want to load the sound files into the exe, extract them to a folder, and then play them directly - take a look at FileInstall and SoundPlay in the Help file. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@Melba: Yeah, but again there's no explanation or context. The example goes

; Example 2
#AutoIt3Wrapper_Res_File_Add=C:WINDOWSMediatada.wav, SOUND, MYWAV
Global Const $SND_RESOURCE = 0x00040004
Global Const $SND_ASYNC = 1
DllCall("winmm.dll", "int", "PlaySound", "str", "MYWAV", "hwnd", 0, "int", $SND_RESOURCE)
DllCall("winmm.dll", "int", "PlaySound", "str", "MYWAV", "hwnd", 0, "int", BitOR($SND_RESOURCE, $SND_ASYNC))
For $n = 1 To 100
    Sleep(15)
    ToolTip("Asynch! " & $n)
Next

But other than the path to the file itself and some sort of dll call, none of this means anything to me, plus I'm inferring that I can't actually use these embedded files with the actual AutoIt functions. For a simpler solution, is it possible to embed the files on compile, then have the script extract them to a temp folder, call on them as needed and delete on exit?

Have a look here for another way to Play a wave file from memory example.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Well, to break it down;

#AutoIt3Wrapper_Res_File_Add=C:WINDOWSMediatada.wav, SOUND, MYWAV

The directive and the path are straightforward enough, but what's the purpose of the the SOUND and MYWAV parameters?

Global Const $SND_RESOURCE = 0x00040004

From the lines afterwards I'm guessing the $SND_RESOURCE refers to the soundfile embedded in the line above - but why that specific value?

Link to comment
Share on other sites

  • Moderators

quinch,

Stop guessing and look at the code and the SciTE Help file in which you found it: :)

In the SciTE Help file:

; Add extra files to the resources
#AutoIt3Wrapper_Res_File_Add=                   ; Filename[,Section [,ResName[,LanguageCode]]] to be added

So looking at the code:

#AutoIt3Wrapper_Res_File_Add=C:WINDOWSMediatada.wav, SOUND, MYWAV

we see that:

- Filename = C:WINDOWSMediatada.wav (what we want to hear)

- Section = SOUND (hardly surprising!)

- ResName = MYWAV (how we refer to the resource later)

The next bit of the code:

Global Const $SND_RESOURCE = 0x00040004
Global Const $SND_ASYNC = 1

You see the Const bit? That indicates that the value concerned is a constant which is usually used in some form of function call - it is easier for us mere humans to understand a textual constant than a "magic number".

And now we play the sound:

DllCall("winmm.dll", "int", "PlaySound", "str", "MYWAV", "hwnd", 0, "int", $SND_RESOURCE)

Call the "winmm.dll" and ask it to run its internal "PlaySound" function on the resource known as "MYWAV" (which we set earlier) which it will find in the "SOUND" section of the resource table (because that is what the constant value means to the DLL).

As I mentioned earlier, the script will pause while the sound plays. If we want it continue, we need to use the ASYNC constant as well - we use BitOR to combine them (see the Setting Styles tutorial in the Wiki to see why :)). The loop just proves that the script does indeed continue:

DllCall("winmm.dll", "int", "PlaySound", "str", "MYWAV", "hwnd", 0, "int", BitOR($SND_RESOURCE, $SND_ASYNC))
For $n = 1 To 100
    Sleep(15)
    ToolTip("Asynch! " & $n)
Next

Clearer now? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...