Monday, June 25, 2012

VB6 Animasi: Animasi Melayang Ala Google Talk

Mengenai animasi melayang pada saat tampil dan sembunyi di systray ala Google Talk menggunakan VB6.
Const IDANI_OPEN = &H1
Const IDANI_CLOSE = &H2
Const IDANI_CAPTION = &H3

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function SetRect Lib "User32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function DrawAnimatedRects Lib "User32" (ByVal hwnd As Long, ByVal idAni As Long, lprcFrom As RECT, lprcTo As RECT) As Long
Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Public Sub ShowMinimzeToSysTray(ByVal hwnd As Long)
Dim rSource As RECT, rDest As RECT
GetWindowRect hwnd, rSource
GetWindowRect FindWindowEx(FindWindow("Shell_TrayWnd", vbNullString), 0, "TrayNotifyWnd", vbNullString), rDest
Call DrawAnimatedRects(hwnd, IDANI_CLOSE Or IDANI_CAPTION, rSource, rDest)
End Sub

Public Sub ShowRestoreFromSysTray(ByVal hwnd As Long)
Dim rSource As RECT, rDest As RECT
GetWindowRect FindWindowEx(FindWindow("Shell_TrayWnd", vbNullString), 0, "TrayNotifyWnd", vbNullString), rSource
GetWindowRect hwnd, rDest
Call DrawAnimatedRects(hwnd, IDANI_OPEN Or IDANI_CAPTION, rSource, rDest)
End Sub

Private Sub Command2_Click()
ShowMinimzeToSysTray hwnd
End Sub

Private Sub Command1_Click()
ShowRestoreFromSysTray Me.hwnd
End Sub
Kode di atas, akan menjadi tidak bermanfaat apabila aplikasi tidak menggunakan/memanfaatkan systray icon untuk menampilkan dan menyembunyikan aplikasi.