Jump to content

Clicking on Tray normal item not unchecking it


c.haslam
 Share

Recommended Posts

In the following script:

#Include <Constants.au3>
;#NoTrayIcon
Opt("TrayOnEventMode",1)
Opt("MustDeclareVars",1)
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown.

global $trayDoubleIt,$TrayExit

$trayDoubleIt = TrayCreateItem("Double it")
TrayItemSetOnEvent(-1,"CB")
TrayCreateItem("")
$TrayExit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"CB")

While True
    sleep(3000)
WEnd

Func CB()
    Switch @TRAY_ID
#cs        
        Case $trayDoubleIt
            If BitAND(TrayItemGetState(@TRAY_ID),$TRAY_CHECKED)<>0 Then
                TrayItemSetState(@TRAY_ID,$TRAY_UNCHECKED)
            ElseIf BitAND(TrayItemGetState(@TRAY_ID),$TRAY_UNCHECKED)<>0 Then
                TrayItemSetState(@TRAY_ID,$TRAY_CHECKED)
            EndIf
#ce
        Case $TrayExit
            Exit
    EndSwitch
EndFunc

  • As presented, the Double it item is neither checked nor unchecked
  • With the commented-out code de-commented, the Double It item is checked when clicked on but subsequent clicks don't uncheck it.
Why?

...chris

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

Hi!

From help:

By default, normal checked menuitems (not radio menuitems) will be automatically unchecked if you click it!

To turn off this behaviour use the value '2' in TrayMenuMode.

Example:

#Include <Constants.au3>
;#NoTrayIcon
Opt("TrayOnEventMode",1)
Opt("MustDeclareVars",1)
Opt("TrayMenuMode", 1 + 2) ; 1 = no default menu, 2 = user created checked items will not automatically unchecked if you click it

global $trayDoubleIt,$TrayExit

$trayDoubleIt = TrayCreateItem("Double it")
TrayItemSetOnEvent(-1,"CB")

TrayCreateItem("")

$TrayExit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"CB")

While True
    sleep(100)
WEnd

Func CB()
    Switch @TRAY_ID
    Case $trayDoubleIt
        If _GetState($trayDoubleIt) Then
            TrayItemSetState($trayDoubleIt, $TRAY_UNCHECKED)
        Else
            TrayItemSetState($trayDoubleIt, $TRAY_CHECKED)
        EndIf
    Case $TrayExit
        Exit
    EndSwitch
EndFunc

Func _GetState($sItem)
    Return BitAND(TrayItemGetState($sItem), $TRAY_CHECKED)
EndFunc
:)
Link to comment
Share on other sites

  • Consider the following code:
#Include <Constants.au3>
;#NoTrayIcon
Opt("TrayOnEventMode",1)
Opt("MustDeclareVars",1)
Opt("TrayMenuMode", 1 + 2) ; 1 = no default menu, 2 = user created checked items will not automatically unchecked if you click it

global $trayDoubleIt,$TrayExit

$trayDoubleIt = TrayCreateItem("Double it")
TrayItemSetOnEvent(-1,"CB")

TrayCreateItem("")

$TrayExit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"CB")

While True
    sleep(100)
WEnd

Func CB()
    Switch @TRAY_ID
    Case $TrayExit
        Exit
    EndSwitch
EndFuncoÝ÷ Ûú®¢×¢g­ërݶ)â-Ç%Ét:.nW¶ÈhºW[zéÜç$yÖòëh"ÔáȬ­æ¶¡zZjº^'^}«¥¶z+©ç$yÙè­zk'¢ÚÚv*&z{¢µé¬Â)em殶¶'®È^rGü¨¹ÉbrH­ßtè¶êç¡÷í+z¯«ºÇ­ëÚç·÷mýtëk#ã(uïêº^!©®²)àÖ)Ó­¬z{¡×¢æåxb±©è®f¥éîצû^®Ø^~*ìµÉbrH­Æªºç$yÙè®f¥éâµéªºG£hʢ׫¦·­¶¡zZvN¡×ºÚ"µÍØÙH  ÌÍÝ^QÝXR]YÑÙ]Ý]J ÌÍÝ^QÝXR]
H[^R][]Ý]J  ÌÍÝ^QÝXR]   ÌÍÕVWÕSÒPÒÑQ
B[ÙB^R][]Ý]J   ÌÍÝ^QÝXR]   ÌÍÕVWÐÒPÒÑQ
B[Y

is only required if Autoit does not behave according to the help. What say you?

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

Your example works fine.

So does

#Include <Constants.au3>
;#NoTrayIcon
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode", 1 ) ; 1 = no default menu

TrayCreateItem("Double it")
TrayItemSetState(-1,$TRAY_CHECKED)
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"CB")
while 1
    sleep (1000)
WEnd

Func CB()
    Exit
EndFunc

Double It is unchecked and checked on successive clicks. So the help is correct when it says

By default, normal checked menuitems (not radio menuitems) will be automatically unchecked if you click it!

I had been assuming that the converse is also true: "By default, normal unchecked menuitems (not radio menuitems) will be automatically checked if you click it!". I now know that this is not part of the design of AutoIt.

My thinking is that there is a design flaw in AutoIt. Perhaps for TrayCreateItem the fourth parameter should have a third value, so it would be "[optional] 0 (default) = create a normal menuitem, 1 = create a menuradioitem, 2 = create a checkable normal menuitem". With value 2, an item could be initially unchecked, and (with TrayMenuMode set to 1), could be successively checked and unchecked without calling TrayItemSetState.

Or perhaps the following should be added to the help: "An initially unchecked menuitem can only be checked when you click on it by setting TrayMenuItem to 2 and calling TrayItemSetState($TRAY_CHECKED)".

Edited by c.haslam
Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

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...