Sign in to follow this  
Followers 0
heken

Changing an icon in runtime (for a shortcut on the Quick Launch toolbar)

3 posts in this topic

How could my au3 script change the displayed icon for a shortcut? I do NOT mean to modify the compiled file (.exe), no.

Actually, I have a very simple autoit script that mutes/sounds the master volume. The .au3 file is located on My documents, but I've created a shortcut on the Quick Launch toolbar. Once there, I've set up the icon manually to let it look like a speaker.

Now, what I desire is to swap the icon from "sound speaker" to "mute speaker" depending on the current master volume status (i.e. every time I click on the shortcut).

To accomplish this, I need to tweak somehow the "shortcut file". Any clue? Thanks.

Share this post


Link to post
Share on other sites



Not exactally what you're looking for, but why go the hard way :)? Instead of indicating the state in the Quicklaunch Bar indicate it in the system-tray, easy to implement

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown.

$exititem       = TrayCreateItem("Exit")

TraySetState()

$start = 0
While 1
    $msg = TrayGetMsg()
    If $msg = $exititem Then ExitLoop
    $diff = TimerDiff($start)
    If $diff > 1000 Then
        $num = -Random(0,100,1) ; negative to use ordinal numbering
        ToolTip("#icon=" & $num)
        TraySetIcon("Shell32.dll",$num)
        $start = TimerInit()
    EndIF
WEnd

Exit

Share this post


Link to post
Share on other sites

Solved!

Not very elegant, but it works.

Const $shortcut = "whatever the location to my shortcut is"
Const $soundSpeaker = 2
Const $muteSpeaker = 3
Dim $actualIcon

; mutes/sounds the master volume
Send("{VOLUME_MUTE}")

; gets the shortcut properties
$details = FileGetShortcut($shortcut)

; swaps the icon
If $details[5] = $soundSpeaker Then
    $actualIcon = $muteSpeaker
Else
    $actualIcon = $soundSpeaker
EndIf

; replace the current shortcut with the proper icon
FileCreateShortcut($details[0], $shortcut, $details[1], $details[2], $details[3], $details[4], "", $actualIcon, $details[6])

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