This paper uses the CImageList class to save a number of pictures, using the draw function at a certain time interval to play out, forming a similar GIF animation effect. This method can play animation in window's client area, on the toolbar, on the status bar. This paper also gives a method to play the animation on the window title bar by using the SetIcon function.
Animation is a relatively continuous number of static pictures at a certain time interval to show the use of human visual principle of the formation of dynamic effects. Inserting animations into your application can add a lot of features to your application and beautify your interface. There are a lot of ways to play the animation in VC, here to introduce an easy way to add similar GIF animation to the application.
First, the principle
In VC there is a CImageList class can manage images in the form of an image list, with the same image size in the image list, the index starting at 0, and each image can be referenced separately. The Microsoft Win32 API provides a series of functions that you can use to create and destroy image lists, display images, add and remove images, and replace, merge, and drag images.
The CImageList class provides common control features for Windows image lists. This control (also known as the CImageList Class) is only available for use in Window 95 and Windows NT version 3.51 or later. The following functions used in this article are briefly described below:
BOOL Create (int cx, int cy, UINT nflags, int ninitial, int ngrow);
This function is used to create an image list. Cx,cy the width and height of each image; nflags the type of image list, whose value can contain only one ilc_color value. Its detailed value see VC online Help.
The number of images initially contained in the ninitial image list; Ngrow the number of images that grow dynamically each time the number of images needs to be changed.
BOOL Draw (cdc* PDC, int nimage, point pt, UINT Nstyle);
This function is used to display an image. The pointer to the PDC target device context, nimage the image index to display, the location of the PT image display, Nstyle image display style, and see online Help.
Hicon extracticon (int nimage);
The function can be used to get a handle to a function.
int Add (Hicon hicon);
This function adds an image to the image list.
You can animate by declaring a CImageList class in your program, calling the CREATE function, creating the class, and then looping through the image with the draw function for a certain amount of time. The Create class has several overloaded functions that can invoke different functions based on different resources, for the sake of simplicity, this article only uses icon resources, more detailed information on the online manual.