|
|
|
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
Const AW_HOR_NEGATIVE = &H2
Const AW_VER_POSITIVE = &H4
Const AW_VER_NEGATIVE = &H8
Const AW_CENTER = &H10 Const AW_HIDE = &H10000
Const AW_ACTIVATE = &H20000
Const AW_SLIDE = &H40000
Const AW_BLEND = &H80000
Const ANIMATION_TIME = 700
Private Declare Function AnimateWindow Lib "user32" _ (ByVal hwnd As Long, _ ByVal dwTime As Long, _ ByVal dwFlags As Long) As Boolean
Private Sub Form_Load()
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
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 ) |
|
|