Adding extra icons to the program resources
Previous Top Next

This script shows how to add additional Icons to the program resources and then use them.
Compile the script and run the exe to see it in action:


; Add icons to the file resource table
; As no resource names are specified, they will be set automatically to 201+
#AutoIt3Wrapper_Res_Icon_Add=C:\Program Files (x86)\AutoIt3\Icons\au3.ico
#AutoIt3Wrapper_Res_Icon_Add=C:\Program Files (x86)\AutoIt3\Icons\au3script_v10.ico
#AutoIt3Wrapper_Res_Icon_Add=C:\Program Files (x86)\AutoIt3\Icons\au3script_v9.ico
#AutoIt3Wrapper_Res_Icon_Add=C:\Program Files (x86)\AutoIt3\Icons\filetype-blank.ico

#include <ButtonConstants.au3>

; Create the GUI
$hGUI = GUICreate("Demo icon resources")
$cButton = GUICtrlCreateButton("", 10, 10, 40, 40, $BS_ICON)
$cLabel = GUICtrlCreateLabel("", 70, 25, 200, 20)
GUISetState(@SW_SHOW, $hGUI)

; Now run through the added icons in the resource table
For $x = 201 To 204
      ; Change the tray icon
      $rc1 = TraySetIcon(@ScriptFullPath, $x)
      ; Change the icon in the button
      $rc2 = GUICtrlSetImage($cButton, @ScriptFullPath, $x)
      GUICtrlSetData($cLabel, "Icon Name: " & $x)

      TrayTip("Added icon: " & $x, "TraySetIcon rc: " & $rc1 & @CRLF & "GUICtrlSetImage rc: " & $rc2, 3)

      ; Allow time for icon to be seen
      Sleep(5000)
Next

; Delete the GUI
GUIDelete($hGUI)

The directives require full pathnames  for the icon files - you may have to adjust those used if you did not carry out a standard installation.