Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Tray to Title and Title to Tray Effect using DrawAnimatedRects API
[ All Languages » VB »  Windows]

Total Hit ( 4357)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


This little snippet will give you an effect so it looks like that your window is flying from system tray or minimizing to system tray depending on which flag you pass to DrawAnimatedRects API.

Create a standard exe project and place the following code in form1 and run the project to see the effect of DrawAnimatedRects api.

Click here to copy the following block
Private Declare Function GetWindowRect Lib "user32" ( _
    ByVal hwnd As Long, lpRect As RECT) As Long

Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" ( _
    ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
    ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindow Lib "user32" ( _
    ByVal hwnd As Long, ByVal wCmd 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 Type RECT
  Left As Long
  Top As Long
  Right As Long
  Bottom As Long
End Type

Private Const GW_CHILD = 5
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDLAST = 1
Private Const GW_HWNDNEXT = 2
Private Const GW_HWNDPREV = 3
Private Const GWL_WNDPROC = (-4)
Private Const IDANI_OPEN = &H1
Private Const IDANI_CLOSE = &H2
Private Const IDANI_CAPTION = &H3
Private Const WM_USER = &H400
Private rctFrom As RECT
Private rctTo As RECT
Private lngTrayHand As Long
Private lngStartMenuHand As Long
Private lngChildHand As Long
Private strClass As String * 255
Private lngClassNameLen As Long
Private lngRetVal As Long

Private Function TitleToTray(frm As Form)

  lngStartMenuHand = FindWindow("Shell_TrayWnd", vbNullString)
  lngChildHand = GetWindow(lngStartMenuHand, GW_CHILD)
  Do
    lngClassNameLen = GetClassName(lngChildHand, strClass, Len(strClass))
    If InStr(1, strClass, "TrayNotifyWnd") Then
      lngTrayHand = lngChildHand
      Exit Do
    End If
    lngChildHand = GetWindow(lngChildHand, GW_HWNDNEXT)
  Loop
  lngRetVal = GetWindowRect(frm.hwnd, rctFrom)
  lngRetVal = GetWindowRect(lngTrayHand, rctTo)
  lngRetVal = DrawAnimatedRects(frm.hwnd, IDANI_OPEN Or IDANI_CAPTION, rctFrom, rctTo)
End Function

Private Function TrayToTitle(frm As Form)

  lngStartMenuHand = FindWindow("Shell_TrayWnd", vbNullString)
  lngChildHand = GetWindow(lngStartMenuHand, GW_CHILD)
  Do
    lngClassNameLen = GetClassName(lngChildHand, strClass, Len(strClass))
    If InStr(1, strClass, "TrayNotifyWnd") Then
      lngTrayHand = lngChildHand
      Exit Do
    End If
    lngChildHand = GetWindow(lngChildHand, GW_HWNDNEXT)
  Loop
  lngRetVal = GetWindowRect(frm.hwnd, rctFrom)
  lngRetVal = GetWindowRect(lngTrayHand, rctTo)
  lngRetVal = DrawAnimatedRects(frm.hwnd, IDANI_CLOSE Or IDANI_CAPTION, rctTo, rctFrom)

End Function

Private Sub Form_Load()
  TrayToTitle Me
End Sub

Private Sub Form_Unload(Cancel As Integer)
  TitleToTray Me
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.