1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
| Module AnimatedMinimizeToTray
Structure RECT
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure
Structure APPBARDATA
Public cbSize As Integer
Public hWnd As IntPtr
Public uCallbackMessage As Integer
Public uEdge As ABEdge
Public rc As RECT
Public lParam As IntPtr
End Structure
Enum ABMsg
ABM_NEW = 0
ABM_REMOVE = 1
ABM_QUERYPOS = 2
ABM_SETPOS = 3
ABM_GETSTATE = 4
ABM_GETTASKBARPOS = 5
ABM_ACTIVATE = 6
ABM_GETAUTOHIDEBAR = 7
ABM_SETAUTOHIDEBAR = 8
ABM_WINDOWPOSCHANGED = 9
ABM_SETSTATE = 10
End Enum
Enum ABNotify
ABN_STATECHANGE = 0
ABN_POSCHANGED
ABN_FULLSCREENAPP
ABN_WINDOWARRANGE
End Enum
Enum ABEdge
ABE_LEFT = 0
ABE_TOP
ABE_RIGHT
ABE_BOTTOM
End Enum
Public Declare Function SHAppBarMessage Lib"shell32.dll" Alias"SHAppBarMessage" (ByVal dwMessage As Integer, ByRef pData As APPBARDATA) As Integer
Public Const ABM_GETTASKBARPOS As Integer = &H5&
Public Const WM_SYSCOMMAND As Integer = &H112
Public Const SC_MINIMIZE As Integer = &HF020
Public Sub AnimateWindow(ByVal ToTray As Boolean, ByRef frm As Form, ByRef icon As NotifyIcon)
' get the screen dimensions
Dim screenRect As Rectangle = Screen.GetBounds(frm.Location)
' figure out where the taskbar is (and consequently the tray)
Dim destPoint As Point
Dim BarData As APPBARDATA
BarData.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(BarData)
SHAppBarMessage(ABMsg.ABM_GETTASKBARPOS, BarData)
Select Case BarData.uEdge
Case ABEdge.ABE_BOTTOM, ABEdge.ABE_RIGHT
' Tray is to the Bottom Right
destPoint = New Point(screenRect.Width, screenRect.Height)
Case ABEdge.ABE_LEFT
' Tray is to the Bottom Left
destPoint = New Point(0, screenRect.Height)
Case ABEdge.ABE_TOP
' Tray is to the Top Right
destPoint = New Point(screenRect.Width, 0)
End Select
' setup our loop based on the direction
Dim a, b, s As Single
If ToTray Then
a = 0
b = 1
s = 0.05
Else
a = 1
b = 0
s = -0.05
End If
'"animate" the window
Dim curPoint As Point, curSize As Size
Dim startPoint As Point = frm.Location
Dim dWidth As Integer = destPoint.X - startPoint.X
Dim dHeight As Integer = destPoint.Y - startPoint.Y
Dim startWidth As Integer = frm.Width
Dim startHeight As Integer = frm.Height
Dim i As Single
For i = a To b Step s
curPoint = New Point(startPoint.X + i * dWidth, startPoint.Y + i * dHeight)
curSize = New Size((1 - i) * startWidth, (1 - i) * startHeight)
ControlPaint.DrawReversibleFrame(New Rectangle(curPoint, curSize), frm.BackColor, FrameStyle.Thick)
System.Threading.Thread.Sleep(15)
ControlPaint.DrawReversibleFrame(New Rectangle(curPoint, curSize), frm.BackColor, FrameStyle.Thick)
Next
If ToTray Then
' hide the form and show the notifyicon
frm.Hide()
icon.Visible = True
Else
' hide the notifyicon and show the form
icon.Visible = False
frm.Show()
End If
End Sub
End Module |