Modify

Opened 17 years ago

Closed 17 years ago

Last modified 16 years ago

#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 TicketCleanup, 17 years ago

Severity: BlockingNone

Automatic ticket cleanup.

comment:2 by anonymous, 17 years ago

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 J-Paul Mesnage, 17 years ago

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 J-Paul Mesnage, 17 years ago

Milestone: 3.3.1.0
Owner: set to J-Paul Mesnage
Resolution: Fixed
Status: newclosed

Fixed in version: 3.3.1.0

Modify Ticket

Action
as closed The owner will remain J-Paul Mesnage.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.