Sign in to follow this  
Followers 0
Knight

Traymenu Item Check/Uncheck..

8 posts in this topic

#1 ·  Posted (edited)

I want to be able to check and uncheck a traymenu item by clicking it. Everything I have tried has failed. The GetState always returns a 68..

If TrayItemGetState($eItem) = $TRAY_CHECKED Then
        TrayItemSetState($eItem, $TRAY_UNCHECKED)
    Else
        TrayItemSetState($eItem, $TRAY_CHECKED)
    EndIf

I tried also

If BitAND(TrayItemGetState($eItem), $TRAY_CHECKED) = $TRAY_CHECKED Then

It also did not work.

Any help is greatly appreciated...

Edited by Knight

Share this post


Link to post
Share on other sites



This works for me.

Opt ("TrayAutoPause", 0)

$Trayitem = TrayCreateItem ("item", -1, -1, 1)

While 1
    If TrayItemGetState ($Trayitem) = ($TRAY_ENABLE + $TRAY_CHECKED) Then
        TrayTip ("Tray", "Unchecked!", 1)
        TrayItemSetState ($Trayitem, $TRAY_UNCHECKED)
    ElseIf TrayItemGetState ($Trayitem) = ($TRAY_ENABLE + $TRAY_UNCHECKED) Then
        TrayTip ("Tray", "Checked!", 1)
        TrayItemSetState ($Trayitem, $TRAY_CHECKED)
    EndIf
    Sleep (5000)
WEnd

Note: when the traytip says "checked", it means that it was unchecked and it just set it to checked. If it says "unchecked", it was just checked and is now unchecked. You can get rid of the TrayItemSetState commands to see it work for yourself.

Share this post


Link to post
Share on other sites

this worked

#Include <Constants.au3>
#NoTrayIcon

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

$chkitem        = TrayCreateItem("Check it")
TrayCreateItem("")
$checkeditem    = TrayCreateItem("Checked")
TrayCreateItem("")
$exititem       = TrayCreateItem("Exit")

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $chkitem
            TrayItemSetState($checkeditem,$TRAY_CHECKED)
            test()
        Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd

Exit


Func test()
    
    If BitAND(TrayItemGetState($checkeditem), $TRAY_CHECKED) = $TRAY_CHECKED Then
        MsgBox(0,"test", "This type of read worked")
    EndIf
    
EndFunc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

they both do not work correctly.

If BitAND(TrayItemGetState($Item), $TRAY_CHECKED) = $TRAY_CHECKED Then
         TrayItemSetState($Item, $TRAY_UNCHECKED)
         
    Else
        
        TrayItemSetState($Item, $TRAY_CHECKED)
    EndIf

It does the else even if it is checked.. however if I remove the else all togethor it will uncheck.. but it cant re-check...

The first example kept checking it, never uncheck it.

Share this post


Link to post
Share on other sites

I figured out the problem..

It must be..

Opt("TrayMenuMode",3)

not..

Opt("TrayMenuMode",1)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Actually it did work. But just to prove it, I'll turn it into a hotkey setup.

Opt ("TrayAutoPause", 0)

$Trayitem = TrayCreateItem ("item", -1, -1, 1)

HotKeySet ("1", "checkme")
HotKeySet ("2", "uncheckme")

While 1
    Sleep (1000)
WEnd

Func checkme()
    TrayTip ("Tray", "Checked!", 1)
    TrayItemSetState ($Trayitem, $TRAY_CHECKED)
EndFunc
Func uncheckme()
    TrayTip ("Tray", "Unchecked!", 1)
    TrayItemSetState ($Trayitem, $TRAY_UNCHECKED)
EndFunc

Press 1, then check the state of the item by right clicking on the tray.

Press 2, then check the state of the item by right clicking on the tray.

It works.

Edit - yes, the mode will make a difference for clicking. I was showing the fact that it correctly checks and unchecks.

Edited by greenmachine

Share this post


Link to post
Share on other sites

it worked for me

#Include <Constants.au3>
#NoTrayIcon

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

$chkitem        = TrayCreateItem("Check it")
TrayCreateItem("")
$checkeditem    = TrayCreateItem("Checked")
TrayCreateItem("")
$test       = TrayCreateItem("Test Checked")
TrayCreateItem("")
$exititem       = TrayCreateItem("Exit")

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $chkitem
            TrayItemSetState($checkeditem,$TRAY_CHECKED)
        Case $msg = $test
            test()
        Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd

Exit


Func test()
    
;If BitAND(TrayItemGetState($checkeditem), $TRAY_CHECKED) = $TRAY_CHECKED Then
;   MsgBox(0,"test", "This type of read worked")
;EndIf
    
    If BitAND(TrayItemGetState($checkeditem), $TRAY_CHECKED) = $TRAY_CHECKED Then
         TrayItemSetState($checkeditem, $TRAY_UNCHECKED)
        MsgBox(0,"test", "The item should be unchecked")
    Else
        
        TrayItemSetState($checkeditem, $TRAY_CHECKED)
        MsgBox(0,"test", "The item should be checked")
    EndIf
EndFunc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Thanks guys, I got it working :o

They both work :geek:

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