Class

# DesktopTrayItem

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

## Description

Used to add items to the System Tray. Windows and Linux only.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                               | Type                                        | Read-Only | Shared |
|------------------------------------|---------------------------------------------|-----------|--------|
| `Handle<desktoptrayitem.handle>`   | `Ptr</api/data_types/additional_types/ptr>` | ✓         |        |
| `Icon<desktoptrayitem.icon>`       | `Picture</api/graphics/picture>`            |           |        |
| `Tooltip<desktoptrayitem.tooltip>` | `String</api/data_types/string>`            |           |        |

## Events

<div class="rst-class">

table-centered_column_4

</div>

| Name                               | Parameters                                            | Returns |
|------------------------------------|-------------------------------------------------------|---------|
| `Pressed<desktoptrayitem.pressed>` | cause As `PressedTypes<desktoptrayitem.pressedtypes>` |         |

## Enumerations

<div id="desktoptrayitem.pressedtypes">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopTrayItem.PressedTypes

### PressedTypes

> The mouse clicks that can occur on a <span class="title-ref">DesktopTrayItem</span>.
>
> | Name        | Description                         |
> |-------------|-------------------------------------|
> | DoubleClick | A double-click occurred.            |
> | LeftClick   | The left mouse button was clicked.  |
> | RightClick  | The right mouse button was clicked. |

## Property descriptions

<div id="desktoptrayitem.handle">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopTrayItem.Handle

**Handle** As `Ptr</api/data_types/additional_types/ptr>`

> Returns the window handle that the <span class="title-ref">DesktopTrayItem</span> belongs to on Windows and the GtkStatusIcon widget on Linux. On Windows, the first <span class="title-ref">DesktopTrayItem</span> has a ID of 1000 and subsequent adds will increment this ID.
>
> This property is read-only.

<div id="desktoptrayitem.icon">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopTrayItem.Icon

**Icon** As `Picture</api/graphics/picture>`

> The icon displayed as the <span class="title-ref">DesktopTrayItem</span>.

<div id="desktoptrayitem.tooltip">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopTrayItem.Tooltip

**Tooltip** As `String</api/data_types/string>`

> Help associated with the <span class="title-ref">DesktopTrayItem</span>.

## Event descriptions

<div id="desktoptrayitem.pressed">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopTrayItem.Pressed

**Pressed**(Cause As `PressedTypes<desktoptrayitem.pressedtypes>`)

> The user has clicked on the <span class="title-ref">DesktopTrayItem</span>.
>
> The parameter *Cause* indicates the type of click.

## Notes

See also the `DesktopApplication.AddTrayItem<desktopapplication.addtrayitem>` method for information on adding a <span class="title-ref">DesktopTrayItem</span>.

## Sample code

Add a class to your project (call it AppTrayItem) and change its super to <span class="title-ref">DesktopTrayItem</span>. Also add a property to the App class:

``` xojo
Tray As AppTrayItem
```

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

This code instantiates it in the App.Opening event handler:

``` xojo
Tray = New AppTrayItem
If Not Self.AddTrayItem(Tray) Then
  ' There was an error adding the TrayItem
End If
```

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

The following code in the Pressed event of the AppTrayItem handles mouse clicks and double-clicks:

``` xojo
Select Case cause
Case DesktopTrayItem.PressedTypes.LeftClick
  MessageBox("Left button clicked")
Case DesktopTrayItem.PressedTypes.DoubleClick
  MessageBox("Double-clicked")
Case DesktopTrayItem.PressedTypes.RightClick
  Var trayMenu As New DesktopMenuItem
  trayMenu.AddMenu(New DesktopMenuItem("About"))
  trayMenu.AddMenu(New DesktopMenuItem("Exit"))

  Var result As DesktopMenuItem
  result = trayMenu.PopUp

  Select Case result.Text
  Case "About"
    MessageBox("The TrayItem example")
  Case "Exit"
    Quit
  End Select
End Select
```

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

When the application quits, you call the RemoveTrayItem method of the `DesktopApplication</api/user_interface/desktop/desktopapplication>` class. This goes in the Closing event handler of the `App</api/language/app>` object.

``` xojo
If Tray <> Nil Then
  Self.RemoveTrayItem(Tray)
End If
```

## Compatibility

|                       |                |
|-----------------------|----------------|
| **Project Types**     | Desktop        |
| **Operating Systems** | Linux, Windows |

<div id="desktoptrayitem.see_also">

<div class="seealso">

`Object</api/data_types/additional_types/object>` parent class; `DesktopApplication</api/user_interface/desktop/desktopapplication>` class.

</div>

</div>
