This sample demonstrates how to add a tray icon in the Explorer tray bar.
You can find the trayicon sample project at:
- Start > Programs > Embarcadero RAD Studio > Samples and then navigate to CPP\VCL\TrayIcon
- Subversion Repository for C++: http://radstudiodemos.svn.sourceforge.net/viewvc/radstudiodemos/branches/RadStudio_XE2/CPP/VCL/TrayIcon/
The application creates a form that allows the user to choose an icon and place it in the tray bar. The form contains two radio buttons to indicate the state in which the icon should be: on or off. To add the selected icon on the tray, select Place on tray. Click Hide to hide the main form, but keep the icon on the tray. The icon has attached a pop-up menu to allow the user to change the state, see the main form even if it was hidden, or exit the application.
How to Use the Sample
- Navigate to Start > Programs > Embarcadero RAD Studio > Samples and open trayicon.cbproj.
- Press F9 or choose Run > Run.
The project contains one source file, traymain.pas, which contains the main form class.
TFormMain, the class corresponding to the main form, handles the system calls to add and modify the icon on the tray bar.
- The TrayMessage method constructs the data structures necessary to call Shell_NotifyIcon, which sends a message to the system tray bar.
- Show and Hide set the visibility of the form to True and False, respectively.