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


The AnimateWindow function enables you to produce special effects when showing or hiding windows. There are three types of animation: roll, slide, and alpha-blended fade.

Step-By-Step Example

- Create a standard exe project
- Add a new form called Form2 (Form1 is added by default)
- Add 6 option buttons and 2 command buttons on the Form1
- Add the following code in Form1 code window

Form1.frm

Click here to copy the following block
Public DoOnLoad As Boolean

Private Sub Command1_Click()
  DoOnLoad = True
  Form2.Show
End Sub

Private Sub Command2_Click()
  DoOnLoad = False
  Form2.Show
End Sub

Private Sub Form_Load()
  Option1.Caption = "Fade Effect"
  Option2.Caption = "Slide Effect (Left to Right)"
  Option3.Caption = "Slide Effect (Right to Left)"
  Option4.Caption = "Center Effect"
  Option5.Caption = "Slide Effect (Top to Bottom)"
  Option6.Caption = "Slide Effect (Bottom to Top)"
  
  Command1.Caption = "Animate Demo On Form_Load"
  Command2.Caption = "Animate Demo On Form_UnLoad"
End Sub

- Add the following code in Form2 code window

Form2.frm

Click here to copy the following block
Const AW_HOR_POSITIVE = &H1   'Animates the window from left to right.
                'This flag can be used with roll or slide animation.

Const AW_HOR_NEGATIVE = &H2   'Animates the window from right to left.
                'This flag can be used with roll or slide animation.

Const AW_VER_POSITIVE = &H4   'Animates the window from top to bottom.
                'This flag can be used with roll or slide animation.

Const AW_VER_NEGATIVE = &H8   'Animates the window from bottom to top.
                'This flag can be used with roll or slide animation.

Const AW_CENTER = &H10     'Makes the window appear to collapse inward if AW_HIDE is used
                'or expand outward if the AW_HIDE is not used.
Const AW_HIDE = &H10000     'Hides the window. By default, the window is shown.

Const AW_ACTIVATE = &H20000   'Activates the window.

Const AW_SLIDE = &H40000    'Uses slide animation. By default, roll animation is used.

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

Const ANIMATION_TIME = 700 'Animation time (Mili seconds)

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

Private Sub Form_Load()
'Set the graphic mode to persistent
  Me.AutoRedraw = True
  If Form1.DoOnLoad = True Then
    If Form1.Option1 = True Then
      DoAnimation Me.hwnd, ANIMATION_TIME, AW_BLEND
    ElseIf Form1.Option2 = True Then
      DoAnimation Me.hwnd, ANIMATION_TIME, AW_HOR_POSITIVE Or AW_SLIDE
    ElseIf Form1.Option3 = True Then
      DoAnimation Me.hwnd, ANIMATION_TIME, AW_HOR_NEGATIVE Or AW_SLIDE
    ElseIf Form1.Option4 = True Then
      DoAnimation Me.hwnd, ANIMATION_TIME, AW_CENTER
    ElseIf Form1.Option5 = True Then
      DoAnimation Me.hwnd, ANIMATION_TIME, AW_VER_POSITIVE Or AW_SLIDE
    ElseIf Form1.Option6 = True Then
      DoAnimation Me.hwnd, ANIMATION_TIME, AW_VER_NEGATIVE Or AW_SLIDE
    End If
  Else
    Me.Print "Check effect on form unload"
  End If
  Me.Refresh
End Sub

Private Sub Form_Unload(Cancel As Integer)
  If Form1.DoOnLoad = False Then
    If Form1.Option1 = True Then
      DoAnimation Me.hwnd, ANIMATION_TIME, AW_BLEND Or AW_HIDE
    ElseIf Form1.Option2 = True Then
      DoAnimation Me.hwnd, ANIMATION_TIME, AW_HOR_POSITIVE Or AW_SLIDE Or AW_HIDE
    ElseIf Form1.Option3 = True Then
      DoAnimation Me.hwnd, ANIMATION_TIME, AW_HOR_NEGATIVE Or AW_SLIDE Or AW_HIDE
    ElseIf Form1.Option4 = True Then
      DoAnimation Me.hwnd, ANIMATION_TIME, AW_CENTER Or AW_HIDE
    ElseIf Form1.Option5 = True Then
      DoAnimation Me.hwnd, ANIMATION_TIME, AW_VER_POSITIVE Or AW_SLIDE Or AW_HIDE
    ElseIf Form1.Option6 = True Then
      DoAnimation Me.hwnd, ANIMATION_TIME, AW_VER_NEGATIVE Or AW_SLIDE Or AW_HIDE
    End If
  End If

  'Unload our form completely
  Set Form2 = Nothing
End Sub
Sub DoAnimation(Win_hWnd As Long, AnimationTime As Long, flag As Long)
  AnimateWindow Win_hWnd, AnimationTime, flag
End Sub

- Press F5 to run the project
- Select effect option and click on Animate on Load/unload buttons


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.