Sign in to follow this  
Followers 0

icons for compiled script - my solution

2 posts in this topic

hello all,

I came across a frustrating issue, and came up with a solution that might be of use to anyone.

I wrote a GUI script, involving many icons. I used GuiCtrlCreateIcon() and GuiCtrlSetImage(), where the filename is the icon filename, located in my script path.

Everything worked well, until I compiled the script. To have my icons in the compiled script, I need to:

1) Add the icons as resources in the wrapper section.

For every call to GuiCtrlCreateIcon() and GuiCtrlSetImage(), I need to:

2) Put @ScriptFullPath instead of the icon file name

3) Change the icon number from -1 to the internal index of the icon resource (starting at -5 and

decreasing by 1 for every icon).

Easy, right? Well, not for a 30-icons-script and dozens of references to function calls! Moreover, if I do that, then when I run the script in its native form (not compiled), then the icons will naturally not display!

So here is my solution:

I replaced GuiCtrlCreateIcon() and GuiCtrlSetImage() with custom functions: AddIcon() and SetIcon(), respectively, accepting the same parameters and returning the same return codes. These functions use the macro @Compiled to decide if to call the original functions with the icon file name or the script filename, etc. I also put the icon names in an array, in the exact same order as in the wrapper section, to easily calculate the icon index number when compiled.

The result script is presented here. Note the wrapper section, the array, the functions, and how they are used. I attach a zip file with the script and icons. To run the script from SciTe, just make sure the icons are in the same path; then you can compile the script and run it without the icons. It works in both scenarios, without need to change the code.

Now, please someone tell me there is a simple solution that I overlooked, maybe something like a wrapper directive like:


Note: this is a small script with minimal number of icons. For my real script, and even if I had a 1000 icons script, it’s exactly the same method, because I didn’t actually write down the icon names in the wrapper section and in the array. I used DIR /B to generate the icons list, and then Excel to format it and paste into the script. If someone’s interested, I can describe this process in more details.

This is just an example and a proof of concept. If you want to implement it, you may need to put some more effort into replacing other icon-related functions, like _GUICtrlTreeView_SetIcon() etc.

#Region AutoIt3Wrapper directives section
;** This is a list of compiler directives used by AutoIt3Wrapper.exe.
;** comment the lines you don't need or else it will override the default settings
;** AUTOIT3 settings
;;#AutoIt3Wrapper_UseX64= ;(Y/N) Use X64 versions for AutoIt3_x64 or AUT2EXE_x64. Default=N
;;#AutoIt3Wrapper_Version= ;(B/P) Use Beta or Production for AutoIt3 and AUT2EXE. Default is P
;;#AutoIt3Wrapper_Run_Debug_Mode= ;(Y/N) Run Script with console debugging. Default=N
;;#AutoIt3Wrapper_Run_SciTE_Minimized= ;(Y/N) Minimize SciTE while script is running. Default=n
;;#AutoIt3Wrapper_Run_SciTE_OutputPane_Minimized= ;(Y/N) Toggle SciTE output pane at run time so its not shown. Default=n
;;#AutoIt3Wrapper_Autoit3Dir= ;Optionally override the base AutoIt3 install directory.
;;#AutoIt3Wrapper_Aut2exe= ;Optionally override the Aut2exe.exe to use for this script
;;#AutoIt3Wrapper_AutoIt3= ;Optionally override the Autoit3.exe to use for this script
;** AUT2EXE settings
;;#AutoIt3Wrapper_Icon= ;Filename of the Ico file to use
;;#AutoIt3Wrapper_OutFile= ;Target exe/a3x filename.
;;#AutoIt3Wrapper_OutFile_Type= ;a3x=small AutoIt3 file; exe=Standalone executable (Default)
;;#AutoIt3Wrapper_OutFile_X64= ;Target exe filename for X64 compile.
;;#AutoIt3Wrapper_Compression= ;Compression parameter 0-4 0=Low 2=normal 4=High. Default=2
;;#AutoIt3Wrapper_UseUpx=N ;(Y/N) Compress output program. Default=Y
;;#AutoIt3Wrapper_UPX_Parameters= ;Override the default setting for UPX.
;;#AutoIt3Wrapper_Change2CUI= ;(Y/N) Change output program to CUI in stead of GUI. Default=N
;;#AutoIt3Wrapper_Compile_both= ;(Y/N) Compile both X86 and X64 in one run. Default=N
;** Target program Resource info
;;#AutoIt3Wrapper_Res_Comment= ;Comment field
;;#AutoIt3Wrapper_Res_Description= ;Description field
;;#AutoIt3Wrapper_Res_Fileversion= ;File Version
;;#AutoIt3Wrapper_Res_FileVersion_AutoIncrement= ;(Y/N/P) AutoIncrement FileVersion After Aut2EXE is finished. default=N
; P=Prompt, Will ask at Compilation time if you want to increase the versionnumber
;;#AutoIt3Wrapper_Res_ProductVersion= ;Product Version. Default is the AutoIt3 version used.
;;#AutoIt3Wrapper_Res_Language= ;Resource Language code . default 2057=English (United Kingdom)
;;#AutoIt3Wrapper_Res_LegalCopyright= ;Copyright field
;;#AutoIt3Wrapper_res_requestedExecutionLevel= ;None, asInvoker, highestAvailable or requireAdministrator (default=None)
;;#AutoIt3Wrapper_res_Compatibility= ;Vista,Windows7 Both allowed separated by a comma (default=None)
;;#AutoIt3Wrapper_Res_SaveSource= ;(Y/N) Save a copy of the Scriptsource in the EXE resources. default=N
; If _Res_SaveSource=Y the content of Scriptsource depends on the _Run_Obfuscator and #obfuscator_parameters directives:
; If _Run_Obfuscator=Y then
; If #obfuscator_parameters=/STRIPONLY then Scriptsource is stripped script & stripped includes
; If #obfuscator_parameters=/STRIPONLYINCLUDES then Scriptsource is original script & stripped includes
; With any other parameters, the SaveSource directive is ignored as obfuscation is intended to protect the source
; If _Run_Obfuscator=N or is not set then
; Scriptsource is original script only
; Autoit3Wrapper indicates the SaveSource action taken in the SciTE console during compilation
; See SciTE4AutoIt3 Helpfile for more detail on Obfuscator parameters
; free form resource fields ... max 15
; you can use the following variables:
; %AutoItVer% which will be replaced with the version of AutoIt3
; %date% = PC date in short date format
; %longdate% = PC date in long date format
; %time% = PC timeformat
; eg: #AutoIt3Wrapper_Res_Field=AutoIt Version|%AutoItVer%
;;#AutoIt3Wrapper_Res_Field= ;Free format fieldname|fieldvalue
;;#AutoIt3Wrapper_Res_Field= ;Free format fieldname|fieldvalue
;;#AutoIt3Wrapper_Res_Field= ;Free format fieldname|fieldvalue
; Add extra ICO files to the resources which can be used with TraySetIcon(@ScriptFullPath, 5) etc
; list of filename of the Ico files to be added, First one will have number 5, then 6 ..etc
;;#AutoIt3Wrapper_Res_Icon_Add= ; Filename[,LanguageCode] of ICO to be added.
#AutoIt3Wrapper_Res_Icon_Add= arrows2-dn-fade.ico
#AutoIt3Wrapper_Res_Icon_Add= arrows2-dn.ico
#AutoIt3Wrapper_Res_Icon_Add= arrows2-plus-fade.ico
#AutoIt3Wrapper_Res_Icon_Add= arrows2-plus.ico
#AutoIt3Wrapper_Res_Icon_Add= arrows2-up-fade.ico
#AutoIt3Wrapper_Res_Icon_Add= arrows2-up.ico
#AutoIt3Wrapper_Res_Icon_Add= arrows2-update-fade.ico
#AutoIt3Wrapper_Res_Icon_Add= arrows2-update.ico
#AutoIt3Wrapper_Res_Icon_Add= arrows2-X-fade.ico
#AutoIt3Wrapper_Res_Icon_Add= arrows2-X.ico
; Add extra files to the resources
;;#AutoIt3Wrapper_Res_File_Add= ; Filename[,Section [,ResName[,LanguageCode]]] to be added.
;;#AutoIt3Wrapper_Res_File_Add= ; Filename[,Section [,ResName[,LanguageCode]]] to be added.
; Tidy Settings
;;#AutoIt3Wrapper_Run_Tidy= ;(Y/N) Run Tidy before compilation. default=N
;;#AutoIt3Wrapper_Tidy_Stop_onerror= ;(Y/N) Continue when only Warnings. default=Y
;;#Tidy_Parameters= ;Tidy Parameters...see SciTE4AutoIt3 Helpfile for options
; Obfuscator
;;#AutoIt3Wrapper_Run_Obfuscator= ;(Y/N) Run Obfuscator before compilation. default=N
; AU3Check settings
;;#AutoIt3Wrapper_Run_AU3Check= ;(Y/N) Run au3check before compilation. Default=Y
;;#AutoIt3Wrapper_AU3Check_Parameters= ;Au3Check parameters
;;#AutoIt3Wrapper_AU3Check_Stop_OnWarning= ;(Y/N) N=Continue on Warnings.(Default) Y=Always stop on Warnings
;;#AutoIt3Wrapper_PlugIn_Funcs= ;Define PlugIn function names separated by a Comma to avoid AU3Check errors
; cvsWrapper settings
;;#AutoIt3Wrapper_Run_cvsWrapper= ;(Y/N/V) Run cvsWrapper to update the script source. default=N
; V=only when version is increased by #AutoIt3Wrapper_Res_FileVersion_AutoIncrement.
;;#AutoIt3Wrapper_cvsWrapper_Parameters= ; /NoPrompt : Will skip the cvsComments prompt
; /Comments : Text to added in the cvsComments. It can also contain the below variables.
; RUN BEFORE AND AFTER definitions
; The following directives can contain: these variables
; %in% , %out%, %outx64%, %icon% which will be replaced by the fullpath\filename.
; %scriptdir% same as @ScriptDir and %scriptfile% = filename without extension.
; %fileversion% is the information from the #AutoIt3Wrapper_Res_Fileversion directive
; %scitedir% will be replaced by the SciTE program directory
; %autoitdir% will be replaced by the AutoIt3 program directory
;;#AutoIt3Wrapper_Run_Before= ;process to run before compilation - you can have multiple records that will be processed in sequence
;;#AutoIt3Wrapper_Run_After= ;process to run After compilation - you can have multiple records that will be processed in sequence
; RUN BEFORE AND AFTER definitions
;;#AutoIt3Wrapper_Add_Constants= ;Add the needed standard constant include files. Will only run one time.

#include <GUIConstantsEx.au3>

#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <Array.au3>

Dim $aEmbeddedIcons[10]=['arrows2-dn-fade.ico' , _
'arrows2-dn.ico' , _
'arrows2-plus-fade.ico' , _
'arrows2-plus.ico' , _
'arrows2-up-fade.ico' , _
'arrows2-up.ico' , _
'arrows2-update-fade.ico' , _
'arrows2-update.ico' , _
'arrows2-X-fade.ico' , _

Global $msg

GUICreate('Icons View',280,75)
; in the following section:
; AddIcon() stands for GuiCtrlCreateIcon()
; SetIcon() stands for GuiCtrlSetImage()

While $msg<>$GUI_EVENT_CLOSE
$msg = GUIGetMsg()

Func AddIcon($sName,$iNum,$x,$y,$w=32,$h=32,$nStyle=$GUI_SS_DEFAULT_ICON,$nExStyle=0)
Local $IconID=0
If @Compiled Then
Return $IconID

Func SetIcon($item_ID,$sFilename,$sName=-1,$nIconType=1)
If @Compiled Then
If GUICtrlSetImage($item_ID,@ScriptFullPath,0-5-_ArraySearch($aEmbeddedIcons,$sFileName),$nIconType) Then
Return True
Return False
If GUICtrlSetImage($item_ID,$sFileName,-1,$nIconType) Then
Return True
Return False

Share this post

Link to post
Share on other sites

No there is no option like that. What you've you created is a workaround, but frankly speaking I've had no issue when testing scripts if the icon isn't displayed until compiling.

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post

Link to post
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
Sign in to follow this  
Followers 0