This post will discuss how to display animated GIF images in the MFC dialog box. Some of the methods of beautification of traditional controls are being researched and will be posted in succession.
This is one of the VS2008 routines used in this thread.
Accessories
gifpicture.rar (138.1 KB)
upload time: 2009-11-25 16:15
download number of times: 1173
One. Shows the description of the GIF picture control class:
No controls can display animated GIF images, either in VC6.0 or VS2008. The only picture control that can display some static pictures. The GIF animated display control class used in this routine is Pictureex. Its definition file is PictureEx.h, and the implementation file for the class is PictureEx.cpp. The member functions and methods for this class are described below:
Program code:BOOL Load (...)--Loads the GIF and prepares the drawing object;
BOOL Draw ()--draws the image or continues the animated display.
void Stop ()-stop animation;
void UnLoad ()-Stops the animation and releases all resources;
void SetBkColor (COLORREF)-Sets the fill color for transparent areas;
COLORREF GetBkColor ()--Gets the current fill color;
BOOL isgif ()-Returns TRUE if the current image is a GIF;
BOOL isanimatedgif ()-Returns True if the current image is an animated GIF;
BOOL isplaying ()-Returns True if the current image is animated;
size GetSize ()--Returns the image size.
int Getframecount ()--Returns the number of frames in the current image;
BOOL getpaintrect (RECT *lprect)--Returns the currently drawn rectangle.
BOOL setpaintrect (const RECT *lprect)--sets the currently drawn rectangle;
Two. Programming Application steps:
1. First download two small GIF animated pictures on the internet, because VS2008 cannot recognize such a file extension, it will pop up the input file type extension, enter a string. This character is used in the code that follows.
2. Create a dialog box for MFC project. Copy the downloaded resource file to the Res folder of the project directory, and then load the two resource files into your project using the Add Resource method.
3. This step is very important. First copy PictureEx.h and PictureEx.cpp to your project directory in my routines, and then add that class to your project.
4. Add two picture controls to the dialog panel to create a control-type static variable for each of them. My routines are named M_gifpicture and M_girl, respectively.
5. All preparations have been completed. Here's how to add code:
Add a sentence in the dialog box class definition file (my routine is GifPictureDlg.h):
Program code:#include "PictureEx.h"
Locate the following two lines:
Program code:cstatic m_gifpicture;
cstatic M_girl;
Change it to:
Program code:Cpictureex m_gifpicture;
Cpictureex M_girl;
In the dialog box, in the implementation file (my routine is GifPictureDlg.cpp), add the following code in the dialog initialization function bool Cgifpicturedlg::oninitdialog ():
Program code:if (m_gifpicture. Load (Makeintresource (IDR_GIF1), _t ("GIF")))//IDR_GIF1 is the ID number of the animated GIF that was added. GIF is the type of file you type when you add
m_gifpicture. Draw ();
if (m_girl. Load (Makeintresource (IDR_GIF2), _t ("GIF" )))
M_girl. Draw ();
Compile the project below and run it to see the animated GIF. I run the result as follows (because it is a screenshot, so there is no animation effect):
Off
topic How to make your own dialog box look better, add some dynamic elements, this is my focus on MFC after the problem of the busy solution.
in this section of this forum, I have sent two of these posts, listed as follows:
1. How to create XP-style button controls http://bbs.bccn.net/thread-292048-1-1.html
2.MFC Display Flash animation programming implementation http://bbs.bccn.net/thread-292047-1-1.html
MFC displays animated GIF pictures