Opened on Apr 30, 2009 at 9:02:31 AM
Closed on May 11, 2009 at 11:54:36 PM
Last modified on Oct 5, 2009 at 8:48:17 PM
#937 closed Bug (Fixed)
TrayItemSetState() and TrayItemGetState()
| Reported by: | anonymous | Owned by: | J-Paul Mesnage |
|---|---|---|---|
| Milestone: | 3.3.1.0 | Component: | AutoIt |
| Version: | 3.3.0.0 | Severity: | None |
| Keywords: | Cc: |
Description
I'm getting an odd result using the TrayItemGetState function. I have written some code to take action when the user clicks an item in my tray menu, depending on its state. The code also toggles the checked state of the item. No matter which state the menu item is in, the call to TrayItemGetState always returns 68. Am I doing something wrong? Here's some example code which always returns 68 on my machine...
#include <Constants.au3>
; Set up Tray Menu...
AutoItSetOption("TrayAutoPause", 0)
AutoItSetOption("TrayMenuMode", 1)
AutoItSetOption("TrayOnEventMode", 1)
$optionsMenu = TrayCreateMenu("Quick Options")
$startOnBoot = TrayCreateItem("Start with Windows", $optionsMenu)
$exitItem = TrayCreateItem("Exit")
TrayItemSetOnEvent($startOnBoot, "SetOptions")
TrayItemSetOnEvent($exitItem, "AppExit")
TrayItemSetState($startOnBoot, $TRAY_UNCHECKED)
while(1)
WEnd
Func SetOptions()
ConsoleWrite("TrayItemGetState = " & TrayItemGetState($startOnBoot) & @LF)
If BitAND(TrayItemGetState($startOnBoot), $TRAY_UNCHECKED) = $TRAY_UNCHECKED Then
TrayItemSetState($startOnBoot, $TRAY_CHECKED)
Else
TrayItemSetState($startOnBoot, $TRAY_UNCHECKED)
EndIf
EndFunc ;==>SetOptions
Func AppExit()
Exit
EndFunc ;==>AppExit
Attachments (0)
Change History (4)
comment:1 by , on Apr 30, 2009 at 11:00:02 AM
| Severity: | Blocking → None |
|---|
comment:2 by , on May 1, 2009 at 3:48:11 PM
Hm thats strange, it's really seems that there is a bug in TrayItemGetState.
Btw, 68 is "64 ($TRAY_ENABLE) + 4 ($TRAY_UNCHECKED)", and 65 is 64 + 1 ($TRAY_CHECKED).
The workaround for now is to use global variable of course:
#include <Constants.au3>
Global $iStartWithWindows = 0
; Set up Tray Menu...
;AutoItSetOption("TrayAutoPause", 0)
AutoItSetOption("TrayMenuMode", 1)
AutoItSetOption("TrayOnEventMode", 1)
$optionsMenu = TrayCreateMenu("Quick Options")
$startOnBoot = TrayCreateItem("Start with Windows", $optionsMenu)
$exitItem = TrayCreateItem("Exit")
TrayItemSetOnEvent($startOnBoot, "SetOptions")
TrayItemSetOnEvent($exitItem, "AppExit")
;TrayItemSetState($startOnBoot, $TRAY_UNCHECKED)
While 1
Sleep(100)
WEnd
Func SetOptions()
$iStartWithWindows = Number(Not $iStartWithWindows)
TrayItemSetState($startOnBoot, $TRAY_UNCHECKED-$iStartWithWindows)
ConsoleWrite("TrayItemGetState = " & $iStartWithWindows & @LF)
EndFunc ;==>SetOptions
Func AppExit()
Exit
EndFunc ;==>AppExit
comment:3 by , on May 11, 2009 at 5:33:20 PM
In fact if you want to manage the check you need to use TrayMenuMode = 3.
With TrayMenuMode = 1 you don't need to do anything as the system will do it for you.
There is a sligh bug today if the item is not check by a TrayItemSetState($startOnBoot, $TRAY_CHECKED)
comment:4 by , on May 11, 2009 at 11:54:36 PM
| Milestone: | → 3.3.1.0 |
|---|---|
| Owner: | set to |
| Resolution: | → Fixed |
| Status: | new → closed |
Fixed in version: 3.3.1.0

Automatic ticket cleanup.