Sign in to follow this  
Followers 0
Floppy

HELP: How to Check if Tray Item exists?

5 posts in this topic




FSoft,

Although you have declared the variable $hello, you have not given it a value - so AutoIt assumes it is 0. Guess what the default return frm GUIGetMsg is when there are no messages in the queue - you got it! So the Case fires every time. Solution: give the variable an intial placehoder value that will never fire! :D

But you have another problem as well. You need to remove the default AutoIt tray items or you wil pause the script each time you click on the icon - then you can never click your "Test" trayitem. But if you remove them, you need to add your own "Exit" tray item - gets complicated doesn't it? :oops:

Here is a little script which shows all that in action: :)

; Remove the default items
Opt("TrayMenuMode", 3)

; Set a ridiculous value for this ControlID
Global $hello = 9999

$test = TrayCreateItem("Test")
$exit = TrayCreateItem("Exit") ; Add our exit item

While 1

    $msg = TrayGetMsg()

    Select

        Case $msg = $test
            MsgBox(0, "", "Test")
            $hello = TrayCreateItem("Hello")

        Case $msg = $hello
            MsgBox(0, "", "Hello")

        Case $msg = $exit ; And look for it here
            Exit

    EndSelect

WEnd

All clear? :rip:

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

#3 ·  Posted (edited)

LOL Thank you Melba!

Please can you give me a range of numbers that I can use to declare tray items? E.g. 99-99999

Edited by FSoft

Share this post


Link to post
Share on other sites

FSoft,

a range of numbers that I can use to declare tray items

You are not declaring the value of the TrayItem - that is set when you use TrayCreateItem. What the 9999 represents is a placeholder value so that the variable holds something and does not fire when TrayGetMsg returns 0. :rip:

Why do I use 9999? Well, ControlIds for normal GUI controls and TrayItems start around 3 and can go up to 65532 (or so they say!). I have never had more than 10000 controls in a GUI (in fact nowhere near that number! :)) and so I felt that 9999 was pretty safe to use as it would be unlikely to match a real ControlID. :D

If you look at the Managing Multiple GUIs tutorial in the Wiki you will see that I use it a lot in the example scripts for exactly the same reason. And you will also see that you can use the same value for all the placeholder values for the predeclared variables - it will be replaced by the real ControlID when the control is actually created. :D

All clear now? :oops:

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

Ok, thank you for your great explaination Melba!

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