Jump to content

Traymenu Item Check/Uncheck..


Recommended Posts

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
Link to comment
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.

Link to comment
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

Link to comment
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.

Link to comment
Share on other sites

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
Link to comment
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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...