Animated Window - Tutorial

Add special effect to your form when it is showing and hiding! 6 types of effects can be applied. They are roll left to right, roll right to left, roll top to bottom, roll bottom to top, expand window outward and fade window. This program shows how to add these fancy effects. Make sure you have Windows 2000 and later or Windows 98 and later running before running this program. The program is well commented and a tutorial is included. Your comments and votes is the way you repay me for my work.

To add special effects when showing your form, 1 API is needed :

AnimateWindow

The AnimateWindow API is easy to use. It is contained in the "user32.dll" library. To call this API, first you need to declare it :

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

You will call the API like this :

AnimateWindow hWnd, dwTime, dwFlags

The parameters for this API :

· hwnd
[in] Handle to the window to animate. The calling thread must own this window.

· dwTime
[in] Specifies how long it takes to play the animation, in milliseconds. Typically, an animation takes 200 milliseconds to play.

· dwFlags
[in] Specifies the type of animation. This parameter can be one or more of the following values.

&H40000
Uses slide animation. By default, roll animation is used. This flag is ignored when used with &H10.

&H20000
Activates the window. Do not use this value with &H10000.

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

&H10000
Hides the window. By default, the window is shown.

&H10
Makes the window appear to collapse inward if &H10000 is used or expand outward if the &H10000 is not used.

&H1
Animates the window from left to right. This flag can be used with roll or slide animation. It is ignored when used with &H10 or &H80000.

&H2
Animates the window from right to left. This flag can be used with roll or slide animation. It is ignored when used with &H10 or &H80000.

&H4
Animates the window from top to bottom. This flag can be used with roll or slide animation. It is ignored when used with &H10 or &H80000.

&H8
Animates the window from bottom to top. This flag can be used with roll or slide animation. It is ignored when used with &H10 or &H80000.

The return values for this API once it is executed is :

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. The function will fail in the following situations:

The window uses the window region.
The window is already visible and you are trying to show the window.
The window is already hidden and you are trying to hide the window.
To get extended error information, call the GetLastError function.

Lastly, wish you have good experiences programming with Visual Basic!

What I Would Like You to Do
- Leave comments about this program at www.planetsourcecode.com/vb/
- Vote for this program at www.planetsourcecode.com/vb/
- Visit my website www.geocities.com/lamrihui/


All contents © Lam Ri Hui 2003