c.haslam Posted March 13, 2008 Share Posted March 13, 2008 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 EndFuncAs presented, the Double it item is neither checked nor uncheckedWith 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 More sharing options...
rasim Posted March 13, 2008 Share Posted March 13, 2008 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 More sharing options...
c.haslam Posted March 13, 2008 Author Share Posted March 13, 2008 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][TÙ]Ý]J ÌÍÝ^QÝXR] ÌÍÕVWÕSÒPÒÑQ B[ÙB^R][TÙ]Ý]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 More sharing options...
rasim Posted March 13, 2008 Share Posted March 13, 2008 Sorry i don`t understand you, my example don`t work? Link to comment Share on other sites More sharing options...
c.haslam Posted March 13, 2008 Author Share Posted March 13, 2008 (edited) 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 March 13, 2008 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now