Jump to content

Can a script change it's own icon


Recommended Posts

I have learned how to use TraySetIcon icon and toggle between icons that I added as resources using 

#AutoIt3Wrapper_Res_Icon_Add=C:\Program Files (x86)\AutoIt3\Icons\au3.ico

My current work around is 

Doit()

Func    Doit()
    Local $TestIcon = @ScriptDir&"\Test.ico"
    Local $ProdIcon = @ScriptDir&"\Prod.ico"
    Local $Test = "Test"
    Local $Prod = "Prod"
    Local $Current = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\My Program","Location")
    If $Current =  $Prod Then
        FileCreateShortcut($Test,@DesktopCommonDir&"\TestLink.lnky",Default,Default,"Test Link",$TestIcon)
        RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\My Program",$Test)
    Else
        FileCreateShortcut($Test,@DesktopCommonDir&"\TestLink.lnky",Default,Default,"Test Link",$ProdIcon)
        RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\My Program",$Prod)
    EndIf

EndFunc

I did a bit of quick cutting, from my working program. Basically it creates an link on the desktop, and then deletes it and creates a new one each time it is run. If you where wondering, I made it a .lnky file so that I could add a custom right click menu for it. 

This example came from a something I am using to switch between prod and test environments, so the actual link created does not launch the script. You can right-click on the link and run the script to change environments. The icon lets me know at a glance which environment I am currently set for. 

 

What I am trying to figure out is if there is a way to change the icon of the executable of the script only using the resources compiled within that script. What would be nice would be to have a ScriptSetIcon function.

Link to comment
Share on other sites

  • Developers
9 minutes ago, amimemeami said:

What I am trying to figure out is if there is a way to change the icon of the executable of the script only using the resources compiled within that script. What would be nice would be to have a ScriptSetIcon function.

Just use the Resource UDF's floating around somewhere or write your own  or simply use reshacker to change the static ico of a compiled script EXE. :)
Do see why that would have to be an function.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

10 minutes ago, Earthshine said:

that would be nice, as well as dynamic desktop icons, but apps probably already do this, Xarmin apps that is.

As far as tray icons go. That is easy with TraySetIcon  

Here is my example code for testing that.. Although it is mostly my own custom icons, but you get the idea

 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\Icons\dog.ico
#AutoIt3Wrapper_Res_Icon_Add=C:\Program Files (x86)\AutoIt3\Icons\unicorn_icon.ico
#AutoIt3Wrapper_Res_Icon_Add=C:\Program Files (x86)\AutoIt3\Icons\au3.ico
#AutoIt3Wrapper_Res_Icon_Add=C:\Program Files (x86)\AutoIt3\Icons\dog.ico
#AutoIt3Wrapper_Res_Icon_Add=C:\Program Files (x86)\AutoIt3\Icons\Yoda.ico

#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

HotKeySet("{ESC}","Terminate")
HotKeySet("i", "IconToggle")
Global $iIcon = 200

;~ ClipPut(@SystemDir)
Main()

Func Main()
    While 1
        Sleep(50)
    WEnd
EndFunc


Func IconToggle()
    $iIcon += 1
    if $iIcon > 204 then $iIcon = 201
    $rc1 = TraySetIcon(@ScriptFullPath,$iIcon)
    ToolTip($iIcon)
EndFunc
Func Terminate()
    Exit
EndFunc

 

Link to comment
Share on other sites

1 hour ago, Jos said:

Just use the Resource UDF's floating around somewhere or write your own  or simply use reshacker to change the static ico of a compiled script EXE. :)
Do see why that would have to be an function.

Jos

Could you point me in the right direction as far as what I am looking for. I looked for Resource UDF's, but I do not see a way of modifying the icon of the executable. I can already add the icons to the compiled script, or are you saying that I could use reshacker as a resource?

Link to comment
Share on other sites

  • Developers
35 minutes ago, Earthshine said:

that would be nice, as well as dynamic desktop icons, but apps probably already do this, Xarmin apps that is.

The SciTE4AutoIt3 contains an example how to update the tray ICO with extra files included by AutoIt3Wrapper directives.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers
8 minutes ago, amimemeami said:

I just realized I was confusing reshacker for a stand alone resource hacker that I had used before. I am looking at the UDF now thanks

I did mean the standalone famous program. ;)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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

×
×
  • Create New...