Sign in to follow this  
Followers 0
JAFN

Switching between custom icons

13 posts in this topic

Hi, let me say up front that while I had a lot of programing experience decades ago I might as well be a complete newbie. If possible I will need to be led by the hand.

I have searched long and hard through the help system and searched for 'Icon' in the faq and here.

In a nutshell, I have a short script that runs in two possible states. I would like to switch between two custom icons in the tray depending on what state the code is in.

I tried several variations of 'TraySetIcon()' but so far with no luck.

Can you point me in the right direction?


[size="2"]The second mouse gets the cheese[/size]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#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

It is Working fine!!!!

or:

include the attatched file into your script and for Example:

#include <ModernMenuRaw.au3>
$f_tray = _TrayIconCreate('tinyMSN', @ScriptDir & '\dll\availible.ico', 'MyTrayTipCallBack')
   $c_cm = _TrayCreateContextMenu($f_tray)
_TrayIconSetState($f_tray, @SW_SHOW)

ModernMenuRaw.au3

Edited by SYRAU3

Share this post


Link to post
Share on other sites

The first is from the help system that seems to work fine with icons from system dlls but appears to not handle custom icons.

Lets say I have two tray icons: StateOn.ico and StateOff.ico. How would I go about loading one or the other as a tray icon?

Thanks


[size="2"]The second mouse gets the cheese[/size]

Share this post


Link to post
Share on other sites

JAFN,

TraySetIcon works both with icons from inside DLLs and standalone icons - I use it all the time. :)

What syntax are you using to display your "custom" icons? All you need is the full path and filename. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

JAFN,

TraySetIcon works both with icons from inside DLLs and standalone icons - I use it all the time. :)

What syntax are you using to display your "custom" icons? All you need is the full path and filename. :)

M23

if $var=0 then
      TraySetIcon("DropBeepUncom.ico")
      soundPlay($sound)
      sleep($alarmPing)
     else
      TraySetIcon("DropBeepCom.ico")
      sleep($waitPing)
   endif
   TraySetState()

icons are in the same directory as the exe.

Are tray icons any different than regular icons?

I used icoFX to create them and they work fine individually if compiled to the script.


[size="2"]The second mouse gets the cheese[/size]

Share this post


Link to post
Share on other sites

JAFN,

Try adding the full path as I suggested: :)

TraySetIcon(@ScriptDir & "\DropBeepUncom.ico")

You could also store the icons inside your exe using #AutoIt3Wrapper_Res_Icon_Add - then you can use them like this:

TraySetIcon(@ScriptFullPath, $iIcon_Index)

The SciTE help file will tell you more - look under <Extra Utilties - AutoIt3Wrapper - Directives Available>. You do need the full SciTE4Autoit3 installation - if you have not got it you can download it here. Well worth the effort - lots of goodies to help you code in Autoit. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

full path did not work.

I had previously tried using:

FileInstall(".\DropBeepCon.ico","..\DropBeepCon.ico",1)

FileInstall(".\DropBeepUncon.ico","..\DropBeepUncon.ico",1)

without success

I will try to figure your other suggestions and get back to you on the amount of success.

Thank you so much for your time.


[size="2"]The second mouse gets the cheese[/size]

Share this post


Link to post
Share on other sites

JAFN,

Post your icons here (or send them in a PM if you prefer) and I will see if I can get them to work on my machine. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Oh man have I justified my handle. Such a stupid mistake that I blame on my bad eyes.

I spelled the icon file names wrong.

So sorry to have wasted your time though I did learn a lot.


[size="2"]The second mouse gets the cheese[/size]

Share this post


Link to post
Share on other sites

JAFN,

Join the club! :)

Glad you got it working.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Can anyone give me a clue as to why this isn't working?

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=d:\temp\temp.exe
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Icon_Add=D:\Media\Icons\Cleanup.ico
#AutoIt3Wrapper_Res_Icon_Add=D:\Media\Icons\PureRa.ico
#AutoIt3Wrapper_Res_Icon_Add=D:\Media\Icons\JavaRa.ico
#AutoIt3Wrapper_Res_Icon_Add=D:\Media\Icons\Defragmentation.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
While 1
    TraySetIcon(@ScriptFullPath,1)
    Sleep(500)
    TraySetIcon(@ScriptFullPath,2)
    Sleep(500)
    TraySetIcon(@ScriptFullPath,3)
    Sleep(500)
    TraySetIcon(@ScriptFullPath,4)
    Sleep(500)
    TraySetIcon()
    Sleep(500)
WEnd
I'm working on a cleanup script and want to be able to show which phase the script is in based on the active icon. When run, it just shows the default icon and nothing else.

I've even used an icon extraction program to confirm that the icons are, indeed, embedded.

I'm also assuming the default AutoIt icon is "0". This is just a sample code, obviously; I want to make sure I get the concept right before putting into my main script.

Share this post


Link to post
Share on other sites

Xander,

AutoIt uses the first 5 icons (0 to -4) so the first icon added by #AutoIt3Wrapper_Res_Icon_Add is indexed as -5, the second as -6, etc. So you need to use those indices. :)

Try this:

While 1
    TraySetIcon(@ScriptFullPath, -5)
    Sleep(500)
    TraySetIcon(@ScriptFullPath, -6)
    Sleep(500)
    TraySetIcon(@ScriptFullPath, -7)
    Sleep(500)
    TraySetIcon(@ScriptFullPath, -8)
    Sleep(500)
    TraySetIcon()
    Sleep(500)
WEnd

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Argh. I had a feeling it was something simple.

I'm surprised, then, that the icon extraction program didn't pull out 4 more icons (1-4). If it had, that would probably have tipped me off.

Plan B was to use the icons from the running Exes themselves but I wanted to get this info into my brain. Thanks.

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