TTrayIcon

Source: source/classes/ttray.prg

Standalone class (not derived from TControl)

TTrayIcon creates and manages an icon in the Windows system tray notification area. It allows applications to run minimized or in the background while providing user interaction via mouse click events, a tooltip, and a context menu. It is commonly used for background services, instant-messenger-style apps, and applications that minimize to the system tray.

Key DATA Members

DATATypeDescription
oWndObjectThe associated main window (hidden or visible)
oWndParentObjectThe parent window for notification forwarding
oIconObjectThe icon displayed in the system tray
cCaptionCharacterTooltip text shown on hover
bLClickedBlockCode block executed on left-click
bRClickedBlockCode block executed on right-click
bLDblClickBlockCode block executed on double-left-click

Methods

MethodDescription
New( oWnd, oIcon, cTip, bLClick, bRClick )Create a new tray icon
End()Remove the icon from the system tray and release resources
Refresh( oIcon, cTip )Refresh the tray icon display
SetIcon( oIcon, cTip )Change the icon and/or tooltip text
SetText( cTitle )Set the caption text

Example: Tray Icon with Menu and Restore on Double-Click

#include "FiveWin.ch"

function Main()

   local oWnd, oTray, oMenu

   DEFINE WINDOW oWnd TITLE "Tray Demo" SIZE 400, 300

   oTray := TTrayIcon():New( oWnd, "app.ico", "My Application",;
      {|| MsgInfo( "Left click" ) },;
      {|| oMenu:Show( oTray ) } )

   oTray:bLDblClick := {|| oWnd:Restore(), oWnd:SetFocus() }

   MENU oMenu POPUP
      MENUITEM "&Restore"   ACTION {|| oWnd:Restore() }
      MENUITEM "&Exit"      ACTION {|| oTray:End(), oWnd:End() }
   ENDMENU

   ACTIVATE WINDOW oWnd CENTERED

return nil

Notes

See Also