View Single Post
  #7  
Old 10-14-2006, 19:54
_Ramirez_
 
Posts: n/a
I think this is what you're looking for. First part is about finding the tray rect and the second one is about checking if animation is disabled.

Text taken from "Minimizing windows to the System Tray" by Matthew Ellis.
http://www.codeproject.com/shell/minimizetotray.asp

Determining the Animation Parameters

It’s not enough to know how to display the animation; we also need to know the start and end position. When minimizing, the “from�?value is simple, you can use the RECT of the window. This gives us the correct width of the window, but the height is going to be larger than the caption bar. This is not a problem, however. We have told Windows that we are animating the caption, so Windows only uses the caption’s height.

The “to�?value is slightly trickier. We need to get the RECT of the system tray. Unfortunately, there is no documented way to do this, and each method we can use has its downside.

The most accurate way of getting the system tray dimensions is to actually get the system tray’s window. Through judicious use of the very handy Spy++ utility, we can see that the system tray is a window of class “TrayNotifyWnd�? which is a child of the top-level window of class “Shell_TrayWnd�? We can easily get these windows using FindWindow, and then simply call GetWindowRect to get the dimensions of the system tray. As this gives the best results, this is the preferable method, but it must be remembered that this is undocumented and utilises window class names and hierarchies that might not exist in future versions of the shell, so mustn’t be relied upon. If this method fails, we drop through to the next method.

The nearest thing we can get to a documented method is to use the SHAppBarMessage function with the ABM_GETTASKBARPOS message. This will return us the bounding rectangle and edge position of the task bar. From this we can tell where the system tray is. If the edge position is the left or the right of the screen, the tray is at the bottom of the task bar. If the edge position is the top or the bottom of the screen, the tray is to the right of the screen. The only problem with this method is that it doesn’t give us the actual coordinates of the system tray, just the rough position - we have to give a default size for the system tray.

There is still the possibility that this will fail. This is really only likely if explorer has been replaced by a third party shell. Many of these shells now support a system tray (Shell_NotifyIcon sends a WM_COPYDATA message to a top level window of class “Shell_TrayWnd�? which is the task bar) If we find this window, we can get some dimensions for the system tray.

If all else fails, we just use a default value in the bottom right of the screen.

Obviously enough, when maximizing, the “to�?and “from�?values are the opposite to when minimizing.


One Last Nicety

Windows allows the animation to be disabled (using a registry setting, or a tool such as the infamous TweakUI), so we must check for that before calling DrawAnimatedRects. This is a simple call to SystemParametersInfo, with the SPI_GETANIMATION value. If the animation has been disabled, the window is simply hidden; otherwise, we call DrawAnimatedRects.
Reply With Quote