Sign in to follow this  
Followers 0
Newbie23

Help with Tray menu/items

6 posts in this topic

I'm pretty new to autoit as you can see, and I'm trying to make a tray menu from where you can choose to disable or enable f.ex a program to run... but i need help from one of you pros. I've read many examples on how to make a tray item/menu, but i just can't make this work... Please answer if it is possible or not, and hopefully what command to use.

this is the script:

#Include <Constants.au3>

#NoTrayIcon

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

$statusitem = TrayCreateMenu("Status")

$onitem = TrayCreateItem("On", $statusitem)

$offitem = TrayCreateItem("Off", $statusitem)

TrayCreateItem("")

$exititem = TrayCreateItem("Exit")

TraySetState()

While 1

$msg = TrayGetMsg()

Select

Case $msg = 0

If $onitem = WHAT_SHOULD_BE_HERE? Then

Msgbox(64,"Example","Example")

EndIf

ContinueLoop

Case $msg = $onitem

TrayItemSetState($offitem,$TRAY_UNCHECKED)

TrayItemSetState($onitem,$TRAY_CHECKED)

Case $msg = $offitem

TrayItemSetState($onitem,$TRAY_UNCHECKED)

TrayItemSetState($offitem,$TRAY_CHECKED)

Case $msg = $exititem

ExitLoop

EndSelect

WEnd

Exit

The thing is that below the Case $msg = 0 i want to it to check if the $onitem is checked, and if it is, then run program... and if not then just wait for it to be checked.

I'm sorry for my english, but i hope someone understand and could take a minute answering...

Thanks for any help.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I haven't done trayitems personally but from the code you've given (which should be in code tags btw) it couldn't you try

#Include <Constants.au3>
#NoTrayIcon

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


$statusitem = TrayCreateMenu("Status")
$onitem = TrayCreateItem("On", $statusitem)
$offitem = TrayCreateItem("Off", $statusitem)
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")

TraySetState()

While 1
$msg = TrayGetMsg()
Select
Case $msg = 0
If $onitem = $TRAY_CHECKED Then
Msgbox(64,"Example","Example")
EndIf
ContinueLoop
Case $msg = $onitem
TrayItemSetState($offitem,$TRAY_UNCHECKED)
TrayItemSetState($onitem,$TRAY_CHECKED)
Case $msg = $offitem
TrayItemSetState($onitem,$TRAY_UNCHECKED)
TrayItemSetState($offitem,$TRAY_CHECKED)
Case $msg = $exititem
ExitLoop
EndSelect
WEnd
Exit

once again, just going from the code you posted but it's a start at least

Edited by dbzfanatic

Share this post


Link to post
Share on other sites

I'm pretty new to autoit as you can see, and I'm trying to make a tray menu from where you can choose to disable or enable f.ex a program to run... but i need help from one of you pros. I've read many examples on how to make a tray item/menu, but i just can't make this work... Please answer if it is possible or not, and hopefully what command to use.

this is the script:

The thing is that below the Case $msg = 0 i want to it to check if the $onitem is checked, and if it is, then run program... and if not then just wait for it to be checked.

I'm sorry for my english, but i hope someone understand and could take a minute answering...

Thanks for any help.

You didn't look closely enough at the help file examples for the various Tray commands. You need the "menuradioitem" option to make it "checked" or "unchecked", and you would use TrayItemGetState() to find out the state:

#Include <Constants.au3>
#NoTrayIcon

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

$statusitem = TrayCreateMenu("Status")
$onitem = TrayCreateItem("On", $statusitem, -1, 1)
$offitem = TrayCreateItem("Off", $statusitem, -1, 1)
TrayItemSetState($offitem, BitOR(TrayItemGetState($offitem), $TRAY_CHECKED))
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            If BitAND(TrayItemGetState($onitem), $TRAY_CHECKED) Then
                ToolTip("On is checked...", 100, 100)
            Else
                ToolTip("On is NOT checked...", 100, 100)
            EndIf
        Case $msg = $onitem
            TrayItemSetState($offitem, $TRAY_UNCHECKED)
            TrayItemSetState($onitem, $TRAY_CHECKED)
        Case $msg = $offitem
            TrayItemSetState($onitem, $TRAY_UNCHECKED)
            TrayItemSetState($offitem, $TRAY_CHECKED)
        Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

any way to make it remember the next time it is run?

Use TrayItemGetState() to read the checked/unchecked status of the items as shown above, and then save those values to the registry with RegWrite(), or to an INI file with IniWrite().

and ya, one more thing, how to change the default 'dot' to 'tick? In the help file, the script example shows a 'tick'...

I'm not sure what you mean by 'tick'...? Both the help file example and my code above show dots next to the selected items for me. Can you post code that shows a 'tick'?

but when i add the following arguments...

...an error appears...if i remove one of the '-1' it appears fine, but with the default 'dot'. Where you see two "-1" parameters they are just "defaults". None of those parameters are for 'tick'. There are still only four valid parameters, per the help file:

TrayCreateItem

--------------------------------------------------------------------------------

Creates a menuitem control for the tray.

TrayCreateItem ( text [, menuID [, menuentry [, menuradioitem]]] )

Your quoted example has five parameters, which is in error.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I don't mean to get you to spoon feed me, but I'm not very familiar the usage of .ini files, as in I know what it can be used for, but not sure how a script can read/write the values and then apply it. I did ask about this matter in anoter topic but sadly no one replied.

I don't really like writing to registry so ya, I'll opt for the .ini file method.

Just check out the descriptions and example scripts that come with IniRead() and IniWrite() in the help file. There very easy and straight forward.

Owh...that's true. But...didn't I see it somewhere...? Oh nevermind, but will this picture do? It's the task bar tray menu :P

If it can't be done, then I'll stick with the 'dots', looks fine anyway :)

It may be possible, but I haven't needed it, so I haven't tried it. That image, BTW, looks more like the right-click context menu of the desktop than a task bar or tray menu. I see what you mean by 'ticks', but don't know if there is an option for that. Those are not 'radioitems' because they are not mutually exclusive within the group, but more like 'checkboxes'.

Maybe others will jump in here who have done that, or recognize the option.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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