Sei sulla pagina 1di 2

Yet Another SysTray Application

===============================
Licence:
Do anything you like with it.
Contact:
Bribobs@mail.com
The world is not short of VB SysTray applications. Many use subclassing controls
, which are complicated, prone to crashing and unnecessary. One of the tray form
's standard events can be re- directed to receive mouse click events over the sy
stray. The event usually used is MouseMove. I wanted an application which encaps
ulated all of the functions usually required for systray applications into a sin
gle form, which can easily be included in projects. The main features required a
re:
*
*
*
*

Events when the tray icon is clicked.


A popup menu.
The ability easily to set the tray icon and tooltip.
The ability to intercept form resize and queryunload events.

The application works as follows:


The main
stray is
e (FSYS)
msystray
zed etc.

application form is loaded; it loads an instance of 'Frmsystray'. Frmsy


initially- and remains- invisible. Frmsystray has a public form variabl
which is set to reference the main application form. This means that Fr
can manipulate the main form, e.g. making it visible, maximized, minimi
in response to mouse events.

Frmsystray also exposes:


(1) A tooltip (string) which sets the tray tooltip
(2) A 'TrayIcon' property. This sets the Frmsystray form icon, which in turn set
s the tray icon. This may be set to a picturebox, Image, form or string.
If picturebox or image, the tray icon is set to the respective picture. If a for
m, the tray icon is set to the form's icon. If a string, if "Default" (case inse
nsitive), the FrmSysTray form icon is set alternately to the "flash1" and "flash
2" pictures on FrmSysTray. Which it is set to is changed when a timer on FrmSysT
ray fires (default interval 1000 ms). This is the default behaviour. If the stri
ng is not "Default", then it is assumed to be a picture or icon filename and it
is loaded.
(3) An Interval integer. This sets the timer interval. Setting to zero disabled
the icon flashing.
(4) A 'Click' event. This is generated whenever the tray icon is clicked, and pa
sses a string describing what happened. By default when the right button is clic
ked a menu pops up which can resize the main form. When the left button is doubl
e clicked the main form is shown.
(5) A 'TIcon' event. This is fired whenever the tray icon is updated. It passes
the FrmSysTray form, whose icon is the same as the tray icon.
(6) A MeResize procedure. This can optionally be called from the main form's res
ize event. It causes the main form to be hidden when minimized, a common feature
of systray applications.
(6) A MeQueryUnload procedure. This can similarly be optionally called from the
main form QueryUnload event. It causes the main form's unloading to be cancelled
if unloadmode is vbFormControlMenu, i.e. if the user chose the Close command fr

om the Control menu on the form. In that case the form is minimized and hidden.
Again, this is a common feature of SysTray applications. To end the program ther
efore, another form unload method must be invoked, e.g. use of the Unload statem
ent.
The example program has the FrmSysTray form, and three different example startup
forms. frmMainSimple has just about the minimum code required to set a flashing
icon in the tray, and does nothing else. FrmMainIntermediate has a little more
functionality, uses the MeResize and MeQueryUnload procedures, and the TIcon eve
nt. frmMainComplicated exposes all of the features of the program; it allows the
tray icon to be set from a form, picture or image, and to the default. The upda
te interval can be changed, as can the tooltip. The default icons can be directl
y changed also. The MeResize and MeQueryUnload procedures can optionally be call
ed.

Potrebbero piacerti anche