Home | What's New | Articles | Code Downloads | Tool Box | Links | Code Snippets  

Windows

Animating Windows

Under Windows 2000 and Windows 98 their is a function called AnimateWindow.

AnimateWindow lets you hide and show windows and specify an animation to occur as this happens.

Place in the General Declarations of a form:

Private Declare Function AnimateWindow Lib "user32" (ByVal hwnd As Long, ByVal dwTime As Long, _
ByVal dwFlags As Long) As Long        

Private Const AW_HOR_POSITIVE = &O1 ' Animate the window from left to right. This flag can be used with roll or slide animation
                                                                       ' It is ignored when used with the AW_CENTER flag.

Private Const AW_HOR_NEGATIVE = &H2 ' Animate the window from right to left. This flag can be used with roll or slide animation.
                                                                        '  It is ignored when used with the AW_CENTER flag.

Private Const AW_VER_POSITIVE = &H4 ' Animate the window from top to bottom. This flag can be used with roll or slide animation.
                                                                      ' It is ignored when used with the AW_CENTER flag.

Private Const AW_VER_NEGATIVE = &H8 ' Animate the window from bottom to top. This flag can be used with roll or slide animation.
                                                                        ' It is ignored when used with the AW_CENTER flag.

Private Const AW_CENTER = &H10 ' Makes the window appear to collapse inward if the
                                                            ' AW_HIDE flag is used or expand outward if the AW_HIDE flag is not used.

Private Const AW_HIDE = &H10000 ' Hides the window. By default, the window is shown.
Private Const AW_ACTIVATE = &H20000 ' Activates the window. Do not use this flag with AW_HIDE.
Private Const AW_SLIDE = &H40000 ' Uses slide animation. By default, roll animation is used.
                                                              ' This flag is ignored when used with the AW_CENTER flag.

Private Const AW_BLEND = &H80000 ' Uses a fade effect. This flag can be used only if hwnd is a top-level window.

To make a form collapse inward and then disappear use: 

AnimateWindow myForm.hwnd, 500, AW_CENTER Or AW_HIDE

To make a form expand outwards and become active use:

AnimateWindow myForm.hwnd, 500, AW_CENTER Or AW_ACTIVATE

For this to work the form must be invisible.

Other effects can be achieved by combining flags, for example to make a form to become  visible diagonally use:

AnimateWindow hwnd, 500, AW_HOR_POSITIVE Or AW_VER_POSITIVE

Drawing attention to a Window using FlashWindow

Place in the General Declarations of a form:

Private Declare Function FlashWindow Lib "user32" (ByVal hwnd As Long, ByVal bInvert As Long) As Long

To make the icon in the taskbar flash use:

FlashWindow MyForm.hwnd, True

Cascading All Windows

Place in the General Declarations of a form:

Private Declare Function simpleCascadeWindows Lib "user32" Alias "CascadeWindows" (ByVal hwndParent As Long, ByVal wHow As Long, ByVal lpRect As Long, ByVal cKids As Long, lpkids As Long) As Integer

To cascade all windows use:

simpleCascadeWindows &O0, &O0, &O0, &O0, &O0

Adding an AboutBox

This code uses the ShellAbout function to display an about box.  The problem with creating a about box with this method is that Microsoft's name appears on it.

Place this in the General Declarations of a form:

Private Declare Function ShellAbout Lib "shell32.dll" Alias "ShellAboutA" (ByVal hwnd As Long, ByVal szApp As String, ByVal szOtherStuff As String, ByVal hIcon As Long) As Long

To display the about box use:

Dim sInfo As String
    sInfo = "Copyright " & Chr(169) & " 2001"
    sInfo = sInfo & "My Large Multi National Software Corp" & vbCrLf
    ShellAbout Me.hwnd, "The Title of my Application", sInfo, Me.Icon

Making a window always stay on Top

Place in the General Declarations of a module:

Private Const HWND_TOPMOST = -&H1
Private Const HWND_NOTOPMOST = -&H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2

Private Declare Sub SetWindowPos Lib "user32" (ByVal hWnd As Long, _
    ByVal hWndInsertAfter As Long, ByVal x As Long, _
    ByVal y As Long, ByVal cx As Long, ByVal cy As Long, _
    ByVal wFlags As Long)
Public Property Let AlwaysOnTop(frm As Form, bOnTop As Boolean)
    Dim lFlag As Long
    If bOnTop = True Then
        lFlag = HWND_TOPMOST
    Else
        lFlag = HWND_NOTOPMOST
    End If
    SetWindowPos frm.hWnd, lFlag, 0&, 0&, 0&, 0&, (SWP_NOSIZE Or SWP_NOMOVE)
End Property

To make a window always appear on top of other windows use:

AlwaysOnTop(Form1) = True