[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
|
|
Here a program that shows what it takes to minimize a program to the system tray. Like many things in this business, it is not as straightforward as one would would think. There is no "Minimize to tray" procedure in Delphi nor even in Windows. So here are the main tricks - documented in lots of places on the Web:
In this demo, you can use the minimize or the close icon to hide the application. In practice, programs would probably use one technique or the other. It is also common for programs that use tray icons to use right clicks for a popup menu to display user action choices. That is not implemented in this demo. While this demo illustrates the function required to use systray icons, there are a number of free Delphi components available to simplify their use.. I would probably "de-componentize" one of these (convert it back to a unit) for use in real applications. Addendum February 14, 2004: I posted SystrayDemo2 today replacing my API calls with a slightly modified version of the freeware component CoolTrayIcon. CoolTrayIcon can be downloaded from a number of sites on the web and the version with my mods is included in the download below. CooltrayIcon looks to be a comprehensive implementation including popup menus, animated icons, hint timing control, etc. . I use the component uninstalled - meaning that my program is responsible for creating the instance and overriding property values from defaults as required. I added Boolean properties automatically restore the application when the tray icon is clicked (ShowFormOnTrayIconClick) and to hide the tray icon when the program is visible (PersistentTrayIcon). I also made the default icon be the icon defined for this program. With these changes, adding the minimize to tray function only requires adding a couple of lines to the FormCreate procedure. Addendum May 7, 2004: The original SystrayDemo program did not switch between tab sheets on a page control after being restored - even thought he restored form looked fine. The one line fix was posted today. - after restoring the form, its Visible property must be set to true. I dug this out from the CoolTrayIcon component in SystrayDemo2. Why is it necessary? Looking at the source code for the Delphi's Visible procedure taught me only that a lot of "behind the scenes" stuff happens in the process and some of it is even necessary!
|
[Feedback] [Newsletters (subscribe/view)] [About me]Copyright © 2000-2018, Gary Darby All rights reserved. |