This is my first ever article. I have been working with so many applications of-late but never thought of publishing any of my work online. I am referring to this site since long, and now I think it's pay back time for me.
If you are familiar with Windows APIs, then you must be aware that they provide a great interface for developing out-of-the-box applications. There are so many of them available for use, but most of the time programmers hesitate to use them because there are some complexities involved in embedding them to the core application.
How To Use the Code
Just download and run the demo to see the animation in action.
How It Works
This article demonstrates the use of one of the Windows APIs called AnimateWindow. The API, among so many others is found in the user32.dll library. Detailed explanation of this API can be found here. A call to this API requires three arguments:
- A handle to the window (form) to be animated
- Animation duration (in milliseconds)
- Some flags describing the type of animation
The purpose of this application is fairly simple. The application will demonstrate the form animation using the
AnimateWindow API. There are two forms in this application. One provides the user with various options that can be used to animate any form. The other just shows the form animation effect in action.
I have created a separate class
WinAPI which is used to declare the constants that are used when calling the API and the API itself. The code for this class looks like this:
public class WinAPI
public const int AW_HOR_POSITIVE = 0X1;
public const int AW_HOR_NEGATIVE = 0X2;
public const int AW_VER_POSITIVE = 0X4;
public const int AW_VER_NEGATIVE = 0X8;
public const int AW_CENTER = 0X10;
public const int AW_HIDE = 0X10000;
public const int AW_ACTIVATE = 0X20000;
public const int AW_SLIDE = 0X40000;
public const int AW_BLEND = 0X80000;
public static extern int AnimateWindow
(IntPtr hwand , int dwTime , int dwFlags) ;
The Animated Child Form
The animated form has very little code in the
Load event, a call to the
static implementation of the original API.
What's more, the form can be animated when it appears and/or disappears.
WinAPI.AnimateWindow (this.Handle, animationTime, flags);
The Parent Form
The parent form is used to set the parameters of the animation and load the animated form. There are 6 buttons in this form in total. Listed below are the types of animations:
- Basic Animations
- Roll Left to Right
- Roll Right to Left
- Roll Top to Bottom
- Roll Bottom to Top
- Roll Collapse
- Roll Fade
- Slide Effect
- Slide Left to Right
- Slide Right to Left
- Slide Top to Bottom
- Slide Bottom to Top
Hope this code helps!!!
- 10th January, 2007: Initial post