Modify

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#937 closed Bug (Fixed)

TrayItemSetState() and TrayItemGetState()

Reported by: anonymous Owned by: Jpm
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 Changed 10 years ago by TicketCleanup

  • Severity changed from Blocking to None

Automatic ticket cleanup.

comment:2 Changed 10 years ago by anonymous

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 Changed 10 years ago by Jpm

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 Changed 10 years ago by Jpm

  • Milestone set to 3.3.1.0
  • Owner set to Jpm
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed in version: 3.3.1.0

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jpm.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.