Jump to content

Confusion about TrayItemSetOnEvent


rbm
 Share

Recommended Posts

The TrayItemSetOnEvent documentation (copied below) seems to say that I can use the itemID returned by TrayCreateItem to hook an event up to the Tray item, but when I do nothing happens and the example code shows using -1 instead of an itemID (e.g. TrayItemSetOnEvent(-1,"ShowInfo")). I'd rather use TrayItemSetOnEvent(7,"myFunction1"), then TrayItemSetOnEvent(9,"myFunction2"), and so on.

Any ideas? Thanks.

TrayItemSetOnEvent

--------------------------------------------------------------------------------

Defines a user-defined function to be called when a tray item is clicked.

TrayItemSetOnEvent ( itemID, "function" )

Parameters

itemID The item identifier (itemID) as returned by a TrayCreateItem function.

function The name of the user function to call.

Return Value

Success: Returns 1.

Failure: Returns 0,

Remarks

OnEvent functions are only called when the option TrayOnEventMode is set to 1 - when in this mode TrayGetMsg is NOT used at all.

Within the called user function the item identifier can be retrieved with @TRAY_ID.

If the function is an empty string "" the previous user-defined is disabled.

Example

#include <Constants.au3>

#NoTrayIcon

Opt("TrayOnEventMode",1)

Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown.

TraySetClick(16) ; Only secondary mouse button will show the tray menu.

$infoitem = TrayCreateItem("Info")

TrayItemSetOnEvent(-1,"ShowInfo")

TrayCreateItem("")

$exititem = TrayCreateItem("Exit")

TrayItemSetOnEvent(-1,"ExitScript")

TraySetState()

While 1

Sleep(10) ; Idle loop

WEnd

Exit

; Functions

Func ShowInfo()

Msgbox(0,"Info","Tray OnEvent Demo")

EndFunc

Func ExitScript()

Exit

EndFunc

Link to comment
Share on other sites

-1 is just a way to use the last created control. If you want to use the control ID you can, eg

$infoitem = TrayCreateItem("Info")
TrayItemSetOnEvent($infoitem,"ShowInfo")
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

-1 is just a way to use the last created control. If you want to use the control ID you can, eg

$infoitem = TrayCreateItem("Info")
TrayItemSetOnEvent($infoitem,"ShowInfo")

Ah, yes, it does work fine. I could only get it to work if I also used:

Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown.

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