Animate tray application windows as they open and close

Have you noticed that when you close the window of a tray application it often doesn’t actually close the application but simply hides the window and leaves the application running in the tray: it effectively minimizes the application to the tray. There’s usually no visual clue that this has happened as there would be if you minimized a normal application.

We can change this behaviour by using the DrawAnimatedRects Windows API function.
Here is a little static class that your tray applications can use to animate the window caption, zooming to the tray when the window closes and zooming from the tray when it opens.

The DoZoom method simply wraps the call to DrawAnimatedRects. GetTrayRect gets the bounding rectangle of the tray area of the task bar. The two public methods ZoomToTray and ZoomFromTray zoom the specified window to and from the tray respectively. The Wnd parameter to these methods should be the window handle of the form that you are zooming to and from the tray.


When your tray application is opening from the tray call TTrayZoom.ZoomFromTray. You may possibly do this in a menu item’s OnClick event handler. When your application is closing to the tray call TTrayZoom.ZoomToTray. This may be done in the form’s OnClose or OnCloseQuery event handlers. Exactly where and when you call TTrayZoom’s methods will vary from application to application.