新凡

  博客园 :: 首页 :: :: 联系 :: 订阅 :: 管理 ::

AnimateChangeStateManager

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Text;
 4 using System.Drawing;
 5 using System.ComponentModel;
 6 using System.Windows.Forms;
 7 
 8 namespace JToolDemo
 9 {
10     public class AnimateChangeStateManager
11     {
12         public static void Animate(IntPtr handle, Rectangle fromRect, Rectangle toRect)
13         {
14             NativeMethods.RECT from = NativeMethods.RECT.FromRectangle(fromRect);
15             NativeMethods.RECT to = NativeMethods.RECT.FromRectangle(toRect);
16             NativeMethods.DrawAnimatedRects(handle, NativeMethods.IDANI_CAPTION, ref from, ref to);
17         }
18 
19         public static void Animate(Form animateForm, Control owner)
20         {
21             Animate(animateForm.Handle, animateForm.Bounds, owner.RectangleToScreen(owner.ClientRectangle));
22         }
23 
24         public static void Animate(Form animateForm, Rectangle bounds, bool minimized)
25         {
26             if (minimized)
27             {
28                 Animate(animateForm.Handle, GetNotificationRect(), animateForm.Bounds);
29             }
30             else
31             {
32                 Animate(animateForm.Handle, animateForm.Bounds, GetNotificationRect());
33             }
34         }
35 
36         private static Rectangle GetNotificationRect()
37         {
38             NativeMethods.RECT rect = new NativeMethods.RECT();
39             IntPtr hwnd = NativeMethods.FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", null);
40             if (hwnd == IntPtr.Zero)
41             {
42                 throw new Win32Exception();
43             }
44 
45             hwnd = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "TrayNotifyWnd", null);
46             if (hwnd == IntPtr.Zero)
47             {
48                 throw new Win32Exception();
49             }
50 
51             hwnd = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "SysPager", null);
52             if (hwnd == IntPtr.Zero)
53             {
54                 throw new Win32Exception();
55             }
56 
57             hwnd = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "ToolbarWindow32", null);
58             if (hwnd == IntPtr.Zero)
59             {
60                 throw new Win32Exception();
61             }
62 
63             NativeMethods.GetWindowRect(hwnd, ref rect);
64 
65             return rect.Rect;
66         }
67     }
68 }

 

posted on 2013-07-16 22:06  新凡  阅读(79)  评论(0)    收藏  举报