CoolTrayIcon package, ver. 4.4.0

CoolTrayIcon is a tray icon component with many properties to customize the icon's behaviour and appearance. Features include:
  • Various mouse and click events
  • Popup menu support
  • Methods for hiding and showing the main form
  • Can move to tray when user minimizes the form
  • Icon animation
  • Interactive balloon hints
  • Can convert bitmaps to icons
  • Design preview for easy experimentation
  • The component can be used in a service
  • Restores tray icon on Explorer crash
TextTrayIcon is descended from CoolTrayIcon. It allows you to show a tray icon with a text of your choice. Features include:
  • Text in any font and color
  • Background color or icon
  • Border

Furthermore includes a lightweight timer class, SimpleTimer.

8 demos included.
Source included.
Freeware.

Get the latest version from http://subsimple.com/delphi.asp.

Troels Jakobsen
troels.jakobsen@gmail.com


CoolTrayIcon, ver. 4.4.0

[Properties] [Methods] [Events]
[Hints] [Known Bugs] [Comments]

CoolTrayIcon is a tray icon component. It allows you to easily implement tray icons in your own applications, with various appearances and behaviors.

Properties

Icon | property Icon: TIcon; The icon to display in the tray. This icon is 16x16 pixels and can be up to 16 colors (4 bit) in Win9x and WinNT 4, 4 billion colors (32 bit) in WinXP, and WinME and Win2000 support icons of a color depth up to the user's display mode. I don't know about Win2003 and Vista, but my guess is 32 bit support. If you use an icon file (*.ico) containing more than one icon, Delphi will use the first icon. If it's not 16x16 pixels it will be scaled, which probably won't look good. |
IconVisible | property IconVisible: Boolean; Whether to display the icon. This property has no effect in design mode. | Default false
Hint | type THintString = ShortString; property Hint: THintString; The tray icon's hint (max 128 chars), which is displayed when you move the mouse cursor over the tray icon. Use #13 as a separator in multi-line hints. NOTE: WinNT doesn't appear to support multi-line hints. NOTE: On some older Windows versions (before IE 5) the hint is max 64 chars. NOTE: The time until the hint window closes is determined by Windows, so don't bother trying to change the interval, because you can't. Setting Application.HintPause and Application.HintHidePause has no effect. |
ShowHint | property ShowHint: Boolean; Whether to show the hint. | Default true
PopupMenu | property PopupMenu: TPopupMenu; The popup menu you want to display when the icon is clicked. | Default true
LeftPopup | property LeftPopup: Boolean; Whether you want the popup menu to pop up when you click the left mouse button. Default is false, meaning only the right button will work. NOTE: LeftPopup must be false (or the popup menu unassigned) if you want to double click the tray icon without displaying the popup menu. LeftPopup must be false if you want CoolTrayIcon to handle a menu that has a default menu item. | Default false
Enabled | property Enabled: Boolean; Works like Enabled for other controls, enabling/disabling keyboard and mouse input. Useful when you want to temporarily disable the popup menu, say while you are displaying an about box or some other modal window. | Default true
IconList | property IconList: TCustomImageList; An ImageList containing icons. If it contains other images than icons, the tray icon won't change when using CycleIcons, but no error occurs. NOTE: When you assign to IconList IconIndex is set to 0. NOTE: In D2 and D3 the property is of type TImageList in stead of TCustomImageList. |
IconIndex | property IconIndex: Integer; The current icon in the assigned iconlist (or 0 if no iconlist is assigned). |
CycleIcons | property CycleIcons: Boolean; Animates the tray icon by cycling through all the icons stored in IconList and assigning them to Icon. When you set CycleIcons to true, it will begin with the first icon in IconList. NOTE: CycleIcons can be true even though you have no IconList. No cycling will occur in that case, but the cycle timer is still active, which will consume some resources. | Default false
CycleInterval | property CycleInterval: Cardinal; The time interval in milisecs. before selecting a new icon from IconList. |
DesignPreview | property DesignPreview: Boolean; Enables you to preview the tray icon in design mode. You can watch what the icon looks like, see its hint, enable/disable it, test the popupmenu, and animate it via CycleIcons. NOTE: Set DesignPreview to false to avoid the design time icon appearing when you run your program. This is only a problem in the Delphi IDE, not in the finished exe-file. I couldn't find a way to kill the design icon in run-time, so you'll have to do it yourself. NOTE: Setting DesignPreview in run-time has no effect. | Default false
Handle | property Handle: HWND; The tray icon's handle. | Read-only
WantEnterExitEvents | property WantEnterExitEvents: Boolean; Whether you would like to receive the OnMouseEnter and OnMouseExit events. These events require an internal timer to be active, so if you have no use for them set WantEnterExitEvents to false to minimize resource usage. | Default false
Behavior | type TBehavior = (bhWin95, bhWin2000); property Behavior: TBehavior; This property does not affect the tray icon's behavior in any visible way. It determines which messages are dispatched to the application when the user interacts with the tray icon (specifically, right mouse clicks result in a WM_RBUTTONDOWN followed by a WM_RBUTTONUP message in Win95 mode, but in Win2000 mode a WM_CONTEXTMENU, NIN_SELECT, or NIN_KEYSELECT message is dispatched. For details, see the Remarks section on this page). Probably the only case where you should consider changing the value of this property, is when you send messages to the tray icon programmatically, using PostMessage or SendMessage. NOTE: This property is public, not published. | Default bhWin95
MinimizeToTray | This property applies only when the owner of the tray icon component is a form. property MinimizeToTray: Boolean; Whether you want to hide the main form instead of minimizing it. The form will hide and the tray icon will show. | Default false

Methods

Refresh function Refresh: Boolean;
Redraws the tray icon. You probably don't need to ever call this method. 		Returns true or false
ShowBalloonHint type TBalloonHintIcon = (bitNone, bitInfo, bitWarning, bitError, bitCustom);
type TBalloonHintTimeOut = 10..60;
function ShowBalloonHint(Title: String; Text: String; IconType: TBalloonHintIcon; TimeoutSecs: TBalloonHintTimeOut): Boolean;
Shows a balloon hint (a kind of "sticky" popup hint). You can use up to 64 chars for the title and up to 255 chars for the text. The hint is visible for 10-60 seconds, or until the user clicks it (or until you programmatically hide it). You cannot show a balloon hint if the tray icon is not showing, and hiding the tray icon hides any balloon hint.
NOTE: Balloon hints are not available in Win95 and Win98. Calling this method in those Windows versions has no effect.
NOTE: From WinXP SP 2 the balloon hint supports a custom icon, which is the tray icon itself (the Icon property). To do this, set IconType to bitCustom. If you want the balloon hint to show a custom icon which is not the same as Icon, you must change Icon before calling ShowBalloonHint, then change Icon back again.
NOTE: The HideBalloonHint method is automatically called by ShowBalloonHint, so you don't get multiple balloon hints.
NOTE: There appears to be a bug with the timeout value in WinXP. See bugs section. 		Returns true or false
HideBalloonHint function HideBalloonHint: Boolean;
Hides the balloon hint (if any). 		Returns true or false
Popup procedure Popup(X, Y: Integer);
Shows the associated popupmenu (if any) at the specified screen coordinates.
PopupAtCursor procedure PopupAtCursor;
Shows the associated popupmenu (if any) at the current cursor coordinates. This method is usually called automatically in response to an OnClick event, but you can call it manually if you want the popupmenu to appear at other times.
BitmapToIcon function BitmapToIcon(const Bitmap: TBitmap; const Icon: TIcon; MaskColor: TColor): Boolean;
Renders and returns an existing icon based on the specified bitmap. The bitmap should be 16x16 pixels. Specify a color to be shown transparently or clNone for no transparency.
NOTE: Bitmaps that are not exactly 16x16 will be scaled up or down. 		Returns true or false
GetTooltipHandle function GetTooltipHandle: HWND;
All tray icons share the same tooltip window (the hint popup). This method returns the tooltip handle. 		Returns handle or 0 if error
GetBalloonHintHandle function GetBalloonHintHandle: HWND;
All applications share the same balloon hint (if supported by the Windows version). This method returns the balloon hint handle. 		Returns handle or 0 if error
GetClientIconPos function GetClientIconPos(X, Y: Integer): TPoint;
Returns the cursor position inside the tray icon. Will return coordinates between (-1,-1) and (16,16). You would expect the coordinates to vary between 0 and 15, but Windows adds a border 1 pixel wide to all tray icons, which is appparently considered to be part of the tray icons. Depending on whether the tray icon has other tray icons as neighbours to the left, right, top, or bottom, the border is inserted as Windows sees fit. So in other words, this method is not exact. You should expect a variation of 2 pixels. If anyone sees a way to patch this, let me know. 		Returns position in a TPoint
SetFocus function SetFocus: Boolean;
Sets focus to the tray icon (if it is visible).
NOTE: Supported from ver. 5.0 of Internet Explorer. 		Returns true or false
ShowMainForm This method applies only when the owner of the tray icon component is a form.
procedure ShowMainForm;
Shows the main form.
NOTE: It is important that you use this method when displaying the form, as it contains important calls that affect how the form and the application display themselves. See the demo app.
HideMainForm This method applies only when the owner of the tray icon component is a form.
procedure HideMainForm;
Hides the main form.
ShowTaskbarIcon This method applies only when the owner of the tray icon component is a form.
procedure ShowTaskbarIcon;
Shows the application's taskbar icon (not to be confused with the tray icon).
HideTaskbarIcon This method applies only when the owner of the tray icon component is a form.
procedure HideTaskbarIcon;
Hides the application's taskbar icon (not to be confused with the tray icon).
NOTE: If you display a child form the taskbar icon will become visible again automatically. This is standard Windows behavior.

Events

OnClick | TNotifyEvent; Works like the similar event for window controls. NOTE: The Click event corresponds to a MouseDown followed by a MouseUp. If no DblClick event is assigned the Click event fires immediately (ie. after the MouseUp). Otherwise it will wait for a small period of time to see if the user clicks again, in which case we have a double click. If no DblClick event is assigned a double click will actually cause the Click event to fire. This is intentional.
OnDblClick | TNotifyEvent; Works like the similar event for window controls.
OnMouseDown | TMouseEvent; Works like the similar event for window controls.
OnMouseUp | TMouseEvent; Works like the similar event for window controls.
OnMouseMove | TMouseMoveEvent; Works like the similar event for window controls.
OnMouseEnter | TNotifyEvent; Fired after the cursor enters the tray icon. Requires the WantEnterExitEvents property to be true.
OnMouseExit | TNotifyEvent; Fired after the cursor leaves the tray icon. Requires the WantEnterExitEvents property to be true.
OnCycle | procedure(Sender: TObject; NextIndex: Integer) of object; Fired just before the icon changes via CycleIcons. Returns the next index in the assigned imagelist.
OnBalloonHintShow | TNotifyEvent; Fired after the balloon hint shows itself. This doesn't have to occur immediately after you call the ShowBalloonHint method. In case another application is already showing a balloon hint, your application must wait for it to close before it gets to show the balloon hint itself. This event will tell you when it has shown the hint. NOTE: Not supported in Win2000. See bugs section.
OnBalloonHintHide | TNotifyEvent; Fired after the balloon hint closes because another application needs to show a balloon hint, or because you called either the ShowBalloonHint or the HideBalloonHint method. NOTE: Not supported in Win2000.
OnBalloonHintTimeout | TNotifyEvent; Fired after the balloon hint closes because it timed out. NOTE: Not supported in Win2000.
OnBalloonHintClick | TNotifyEvent; Fired when the user clicks the balloon hint. NOTE: Not supported in Win2000.
OnMinimizeToTray | This event applies only when the owner of the tray icon component is a form. TNotifyEvent; Fired when the application is about to minimize to tray. Useful if you want to do special processing, like animation effects, when the app. gets minimized (hidden). NOTE: MinimizeToTray must be true for this event to fire.
OnStartup | This event applies only when the owner of the tray icon component is a form. procedure(Sender: TObject; var ShowMainForm: Boolean) of object; Fired initially at application startup when the main form is about to display. Set the ShowMainForm parameter to false if you don't want the form to display. NOTE: May fire multiple times for an MDI form (once for every child form created at startup). NOTE: This event occurs before the form's OnCreate method (if used with a form). NOTE: Replaces the StartMinimized property found in earlier versions.

Hints

  • How do I start my app. with the tray icon visible and the main form invisible?
    At design time set IconVisible to true and set the form's Visible property to false. Set the ShowMainForm parameter to false in the OnStartup event. See the StartHidden demo.
  • What is the proper way to restore the form?
    ALWAYS use the method ShowMainForm! This method contains important calls that affect how the form and the application display themselves. Simply setting the form visible or calling Application.Restore is not enough. A common symptom is the form with tabpages that don't update themselves because ShowMainForm wasn't used.
  • I used the OnStartup event to hide the form, but I can still see a quick flash on the taskbar when the app. is starting?
    If it bothers you you can set the Application.ShowMainForm property in the main project source, like this:
      .....
  Application.Initialize;
  Application.ShowMainForm := False;
  .....
  • Why does the tray icon not appear in my NT/2000/XP service app.?
    Set the service's Interactive property to true, set ServiceType to stWin32, and set the tray icon's IconVisible property to true. See also the bugs section concerning services in NT4.
  • I want multiple tray icons in my app.?
    Just create a CoolTrayIcon object for each tray icon you want. The component is optimized to share resources between the tray icons.
  • How do I send a message to the tray icon through code?
    Use PostMessage or SendMessage and specify the message as the LParam parameter. Here's an example of sending a WM_LBUTTONDOWN message, invoking the tray icon's OnMouseDown event:
      PostMessage(CoolTrayIcon1.Handle, WM_TRAYNOTIFY, Integer(CoolTrayIcon1), WM_LBUTTONDOWN);
  • I want to hide ALL windows, including dialogs and popup forms?
    Minimize the app. before calling HideMainForm, like this:
      Application.Minimize;
  CoolTrayIcon1.HideMainForm;
  • I want to override the "hide inactive tray icons" feature in WinXP?
    Calling the tray icon's Refresh method at regular intervals should do the trick (I think). Anyway, it's not a good idea to override standard Windows behavior.
  • When does the OnStartup event occur?
    The OnStartup event occurs before the owner form's OnCreate event.
  • How do I show the balloon hint for less than 10 seconds?
    Set a timer to close the hint prematurely, using the HideBalloonHint method.
  • How do I check if balloon hints are available (since they don't work in Win95 and Win98)?
    This should work in D4 and up:
      uses ComCtrls;
  if (GetComCtlVersion < ComCtlVersionIE4) or
     ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
      (Win32MinorVersion <> 90)) then
    // Balloon hints NOT supported
  • Can I use the ballon hints without the tray icon?
    Take a look at the zBalloon component.

Known Bugs

  • It appears there's a bug in WinXP (apparently both with SP 1 and SP 2 versions of WinXP - possibly it's a general bug independent of service packs). The bug makes the balloon hint appear for a random amount of time, no matter which timeout value you specify in the call to ShowBalloonHint. I haven't verified this with Microsoft, but it is not a problem in other Windows versions. Also, other tray icon components suffer from this problem, so it is most likely an issue with WinXP. Please tell me if you have this problem and you are not running WinXP SP 1 or SP 2.
  • Some people report that the balloon hint events never fire. This is a Win2000 issue. It doesn't appear to matter which service pack, Internet Explorer version, or comctl32.dll version you use. This makes me suspect that Win2000 simply does not support these events.
  • The tray icon may disappear in NT4 if it is used in an interactive service and you log off, then log back on. I've been trying to fix this, but have so far been unsuccessful. An explanation for why the problem occurs can be found here. (BTW: some service packs, like SP6 seem to fix this problem).
  • It is possible to disable balloon hints in Windows. If the balloon hint doesn't display when it's supposed to (and if you're not using Win9x), you should verify this setting.
  • Occasionally someone reports that an application using CoolTrayIcon prevents the user from logging off or shutting down until he manually terminates the application. I've more or less come to the conclusion that this is not a bug in CoolTrayIcon. More likely it's a bug in some other third party component. At least it seems people always get this error when they use CoolTrayIcon together with other third party components. If you get this error try removing the other components one at a time and see if that doesn't solve the problem (or even simpler - run my demo app. and see if it has the problem). Afterwards, if you still have reason to believe CoolTrayIcon is the problem, don't hesitate to tell me, but please perform this simple test of exclusion first. (NOTE: It would seem various components in Delphi's FastNet collection have this problem - independently of CoolTrayIcon).

    Also make sure you use CoolTrayIcon correctly. If your app. "closes to tray" (goes to the tray when the user clicks the form's close button) you need to handle the WM_QUERYENDSESSION message manually, or the app. (unsurprisingly) won't terminate when Windows shuts down. See the source in the CoolTrayTest demo for a solution.
  • If you're using CoolTrayIcon with an ActionList (associated with popup menu items), you'll find that actions based on TCustomAction (like TFileExit) don't execute if the form that owns the tray icon is invisible. I'm guessing TCustomAction is designed to behave like this. However, this problem doesn't occur with standard actions.

Comments

The CoolTrayIcon component is free for personal and commercial use. Feel free to use and improve it, but please include all original files if you redistribute the zip-file. If you have any comments or corrections to the component I would very much like to hear them. A lot of Delphi programmers have already told me they like the component and use it, which is a huge boost for my ego. Thanks a lot, guys - especially those of you who gave suggestions and pointed out the bugs.

If you use the component some credit somewhere in your application would be a nice gesture, but it is not a requirement.

The component should work on any Windows platform (Win9x, ME, NT, 2000, XP, 2003, Vista). If you experience any problems related to the operating system you use, please tell me. Also, it should work in Delphi 3 and up (Delphi 2?) and C++Builder 3 and up. Again, tell me if I'm wrong.

A word about services: CoolTrayIcon does not require its owner to be a form. This allows you to use it for non-windowed apps. such as services. Some of the properties, methods, and events don't make sense without a form, but rather than creating a superclass without these properties/methods/events I've simply let them stay in CoolTrayIcon itself. You can use them in your service app., but they will not do anything. I figured the component would be more flexible and easier to extend into subclasses this way.

Get the latest version from http://subsimple.com/delphi.asp.

Troels Jakobsen
troels.jakobsen@gmail.com


TextTrayIcon, ver. 1.2.1

[Properties] [Methods] [Events]
[Hints] [Known Bugs] [Comments]

TextTrayIcon is a tray icon component. It is an extended version of the CoolTrayIcon component, so you need CoolTrayIcon to make it work.

TextTrayIcon allows you to easily show custom text inside the tray icon. If you need tray icons with just regular icons I suggest you use CoolTrayIcon in stead.

This document describes only the added features of TextTrayIcon. For an explanation of all the standard features of this tray icon component, see the CoolTrayIcon documentation.

Properties

Text property Text: String;
The text to show in the tray icon. The text is always centered horizontally and vertically.
NOTE: You can have multiple lines of text. Separate the lines with #13 (CR).
Font property Font: TFont;
The font to use when drawing the text.
Color property Color: TColor;
The (background) color of the tray icon. Use clBtnFace to show it in the color of the task bar. 		Default clBtnFace
Border property Border: Boolean;
Whether to draw a border at the edges of the tray icon. This is a rectangle 1 px. wide using the color specified by BorderColor. 		Default false
BorderColor property BorderColor: TColor;
The color of the tray icon's border rectangle. 		Default clBlack
BackgroundIcon property BackgroundIcon: TIcon;
If no background icon is specified the tray icon will be rendered using the text, font, color, and border properties you've specified. If a background icon is specified then it will be rendered beneath the text as if the tray icon was transparent. In other words: the background color is ignored and the background icon is shown in stead. 		Default true
Options You will likely prefer to adjust the text inside the tray icon. Use the following layout options for that purpose:
OffsetX | property OffsetX: Integer; Adjusts the text X pixels horizontally.
OffsetY | property OffsetY: Integer; Adjusts the text Y pixels vertically.
LineDistance | property LineDistance: Integer; Adds or deletes pixels between multiple lines of text. A value of -2 is a good idea in most cases of multiline text.

Methods

Draw procedure Draw;
Redraws the tray icon using the current colors, font, and border properties described above.
NOTE: The tray icon is automatically redrawn when one of those properties change.
NOTE: Calling Draw directly (or by assigning to one of the properties mentioned) will set CycleIcons to false, as it doesn't make sense to draw an icon and then immediately replace it with a new one.

Events

No new events.

Hints

  • What are some good rules for showing text in a tray icon?
    You only have 16x16 pixels to draw inside, so use only 1 or 2 lines of text. Use high contrast colors, like white background and black text, perhaps with a border. Don't use fonts with serifs. For multiline text I think the font 'Small Fonts' approx. size 6 looks best. Set OffsetY to -1 and LineDistance to -2. NOTE: It's easy to experiment if you enable the DesignPreview property.
  • How do I start my app. with the tray icon visible and the main form invisible?
    At design time set IconVisible to true and set the form's Visible property to false. Set the ShowMainForm parameter to false in the OnStartup event. See the StartHidden demo.
  • What is the proper way to restore the form?
    ALWAYS use the method ShowMainForm! This method contains important calls that affect how the form and the application display themselves. Simply setting the form visible or calling Application.Restore is not enough. A common symptom is the form with tabpages that don't update themselves because ShowMainForm wasn't used.

Known Bugs

See the bugs documentation for the CoolTrayIcon component.

Comments

The TextTrayIcon component is free for personal and commercial use (along with the CoolTrayIcon component). Feel free to use and improve it, but please include all original files if you redistribute the zip-file. If you have any comments or corrections to the component I would very much like to hear them.

The component should work on any Windows platform (Win9x, ME, NT, 2000, XP, 2003, Vista). If you experience any problems related to the operating system you use, please tell me. Also, it should work in Delphi 3 and up (Delphi 2?) and C++Builder 3 and up. Again, tell me if I'm wrong.

Get the latest version from http://subsimple.com/delphi.asp.

Troels Jakobsen
troels.jakobsen@gmail.com


SimpleTimer, ver. 2.0.3

[Properties] [Methods] [Events] [Stand-alone Methods]
[How To Use] [Known Bugs] [Comments]

SimpleTimer is a timer class. It has the same timer resolution as TTimer, but it is more lightweight because it's derived from TObject in stead of TComponent. Furthermore, the same handle is shared between multiple instances of SimpleTimer. This makes it ideal for developers who need a timer in their own components or applications, but want to keep the resource usage minimal.

Properties

Enabled | property Enabled: Boolean; Enables (starts) or disables (stops) the timer. | Default False
Interval | property Interval: Cardinal; The interval of the timer in millisecs. NOTE: Specifying a value of 0 will cause the timer to stop, but will not set the Enabled property to false. | Default 1000
AutoDisable | property AutoDisable: Boolean; If true, the timer will disable itself (Enabled is set to False) immediately after the next time it fires. Useful when you want a one-shot timer. | Default False

Methods

Create | constructor Create; Creates a new TSimpleTimer object.
CreateEx | constructor CreateEx(AInterval: Cardinal; AOnTimer: TNotifyEvent); Creates a new TSimpleTimer object with the specified Interval property and OnTimer event.
Destroy | destructor Destroy; override; Destroys the TSimpleTimer object.

Events

OnTimer property OnTimer: TNotifyEvent;
Called when the timer fires.

Stand-alone Methods

GetSimpleTimerCount | function GetSimpleTimerCount: Cardinal; Returns the number of TSimpleTimer objects currently allocated.
GetSimpleTimerActiveCount | function GetSimpleTimerActiveCount: Cardinal; Returns the number of TSimpleTimer objects that are currently active (enabled).

How To Use

This example creates a SimpleTimer object, initializing Interval to 500 milliseconds and the OnTimer event to TForm1.TimerProc1, then starts the timer:
procedure TForm1.FormCreate(Sender: TObject);
begin
  SimpleTimer1 := TSimpleTimer.CreateEx(500, TimerProc1);
  SimpleTimer1.Enabled := True;
end;
This is what TimerProc1 might look like:
procedure TForm1.TimerProc1(Sender: TObject);
begin
  ListBox1.Items.Add('SimpleTimer1 fired');
end;
Remember to destroy the SimpleTimer object when your app. terminates.

Known Bugs

  • You may experience occasionally that you lose a timer event when you work with small intervals (approx. below 100 ms.). This is normal, and the same thing happens with a TTimer object. If you want precision you need a multimedia timer, not TTimer or TSimpleTimer which use the low-priority WM_TIMER message. WinXP has better handling of timers and will generally lose fewer timer events than other Windows versions.

Comments

SimpleTimer is free for personal and commercial use. Feel free to use and improve it, but please include all original files if you redistribute the zip-file. If you have any comments or corrections I would very much like to hear them.

Get the latest version from http://subsimple.com/delphi.asp.

Troels Jakobsen
troels.jakobsen@gmail.com


CoolTrayIcon Hints

  • How do I start my app. with the tray icon visible and the main form invisible?
    At design time set IconVisible to true and set the form's Visible property to false. Set the ShowMainForm parameter to false in the OnStartup event. See the StartHidden demo.
  • What is the proper way to restore the form?
    ALWAYS use the method ShowMainForm! This method contains important calls that affect how the form and the application display themselves. Simply setting the form visible or calling Application.Restore is not enough. A common symptom is the form with tabpages that don't update themselves because ShowMainForm wasn't used.
  • I used the OnStartup event to hide the form, but I can still see a quick flash on the taskbar when the app. is starting?
    If it bothers you you can set the Application.ShowMainForm property in the main project source, like this:
      .....
  Application.Initialize;
  Application.ShowMainForm := False;
  .....
  • Why does the tray icon not appear in my NT/2000/XP service app.?
    Set the service's Interactive property to true, set ServiceType to stWin32, and set the tray icon's IconVisible property to true. See also the     bugs section concerning services in NT4.
  • I want multiple tray icons in my app.?
    Just create a CoolTrayIcon object for each tray icon you want. The component is optimized to share resources between the tray icons.
  • How do I send a message to the tray icon through code?
    Use PostMessage or SendMessage and specify the message as the LParam parameter. Here's an example of sending a WM_LBUTTONDOWN message, invoking the tray icon's OnMouseDown event:
      PostMessage(CoolTrayIcon1.Handle, WM_TRAYNOTIFY, Integer(CoolTrayIcon1), WM_LBUTTONDOWN);
  • I want to hide ALL windows, including dialogs and popup forms?
    Minimize the app. before calling HideMainForm, like this:
      Application.Minimize;
  CoolTrayIcon1.HideMainForm;
  • I want to override the "hide inactive tray icons" feature in WinXP?
    Calling the tray icon's Refresh method at regular intervals should do the trick (I think). Anyway, it's not a good idea to override standard Windows behavior.
  • When does the OnStartup event occur?
    The OnStartup event occurs before the owner form's OnCreate event.
  • How do I show the balloon hint for less than 10 seconds?
    Set a timer to close the hint prematurely, using the HideBalloonHint method.
  • How do I check if balloon hints are available (since they don't work in Win95 and Win98)?
    This should work in D4 and up:
      uses ComCtrls;
  if (GetComCtlVersion < ComCtlVersionIE4) or
     ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
      (Win32MinorVersion <> 90)) then
    // Balloon hints NOT supported
  • Can I use the ballon hints without the tray icon?
    Take a look at the zBalloon component.


CoolTrayIcon Demos

The following demos are distributed with CoolTrayIcon:

Name | Description
CoolTrayTest | Main demo of CoolTrayIcon features
TextTrayTest | Main demo of TextTrayIcon features
StartHidden | How to determine at runtime if your app. should start visible or not
CoolService | A simple interactive service using CoolTrayIcon
TrayDraw | A demo of the CoolTrayIcon.BitmapToIcon method
CustomHint1 | Modifying the common tray icon tooltip, changing the font and colors
CustomHint2 | Replacing the tray icon tooltip with your own custom tooltip
MinimizeAnimation | Animation effect when user minimizes a form

CustomHint1 was more or less a port of a VB project by Eduardo A. Morcillo (http://www.domaindlx.com/e_morcillo).
CustomHint2 was made by Zeljko Avramovic and modified by me.
All other demos were made by me.

If you have a cool demo demonstrating how to accomplish a task with CoolTrayIcon or TextTrayIcon, send it to me.


CoolTrayIcon Hints

How to install the components

*** YOU NEED TO INSTALL THE COMPONENTS BEFORE OPENING THE DEMOS IN DELPHI. ***

If you're running Delphi 5 or later:

  1. Open CoolTrayIcon_D5.dpk (Delphi 5) or CoolTrayIcon_D6plus.dpk (Delphi 6 or later) either by doubleclicking the file or by selecting "Open Project" inside Delphi. (CoolTrayIcon_D5.dpk may work for older Delphi versions as well, but I don't know for sure. Please tell me if I'm right.)
  2. Click Compile, then Install.
  3. You may need to add the folder containing the components to your library path (select Tools -> Environment Options from the menu).
  4. That's it. The components should be visible in the component palette in a tab called "Tray Icons" (if older versions of the components were already installed they may be found in "Custom").

If you're running Delphi versions older than ver. 5:

  1. Try the steps above with the CoolTrayIcon_D5.dpk file (it may work in older versions of Delphi, but I don't know for sure. Please tell me). If this doesn't work then do the following:
  2. Select "Install Component" from the "Component" menu item (may vary depending on your Delphi version).
  3. A dialog displays where you must select the components to install and the package to install into. I recommend creating a new package, if you haven't already done so, rather than installing into the default package.
  4. Browse for the RegisterTrayIcons.pas file and select OK.
  5. You may need to add the folder containing the components to your library path (select Tools -> Environment Options from the menu).
  6. That's it. The components should be visible in the component palette in a tab called "Tray Icons" (if older versions of the components were already installed they may be found in "Custom").

If you're running C++ Builder:

The required steps are the same as in Delphi, so just follow the steps above. Alternatively, use this approach:

  1. Select "New Component..." from the menu
  2. In "Ancestor type", select "TTrayIcon [trayicon]"
  3. In "Class Name", type "TCoolTrayIcon"
  4. In "Palette Page", type "Tray Icons" (or another tab you want to install to)
  5. In "Unit file name", select "RegisterTrayIcons.pas" (which is found in the CoolTrayIcon package). Also, include CoolTrayIcon.pas and TextTrayIcon.pas, or you might get an error regarding "IMGLIST.OBJ".
  6. Click on the "Install" button.