MFC add GIF animations
Display GIF animation, this is used in the Cpictureex class library, can be found from the Internet, the following step by step to achieve the display GIF animation.
1, create a dialog box, add a picture control and a text control on the dialog, the effect is as follows:
2, the figure of the gray block is the picture control, to modify its properties will become a gray block, modified two properties, such as:
3. Select the picture control, Ctrl + double-click to add a member variable to it:
// cstatic M_gifctrl; Cpictureex M_gifctrl;
Add the variable is cstatic M_gifctrl, we change it to Cpictureex M_gifctrl, of course, to add Cpictureex header file, in the header file of the dialog box to add:
" PictureEx.h "
4. Add the following code to the OnInitDialog () function of the dialog box to display the animated GIF image:
1 BOOL Cdlgwaiting::oninitdialog ()2 {3 Cdialogex::oninitdialog ();4 5CString strfile = GetAbsolutePath () + _t ("Waiting.gif");6 if(M_gifctrl.load (strfile))7 {8 M_gifctrl.draw ();9 }Ten returnTRUE; One}
Note: I use VS2012, if the GIF file is added to the project's resources, the 6th line uses the load resource to load the GIF, then the final display is a gesture image, not a dynamic picture.
Here I put the GIF picture in the executable file directory, so call the GetAbsolutePath () function to get the directory to execute the file, the GetAbsolutePath () function code is as follows:
1 //get all paths to the execution file2 CString GetAbsolutePath ()3 { 4 CString strtemp; 5TCHAR *pbuf =Strtemp.getbuffer (MAX_PATH);6 7 :: GetModuleFileName (NULL, PBuf, MAX_PATH); 8 Strtemp.releasebuffer ();9strtemp = Strtemp.left (Strtemp.reversefind (_t ('\\')) + _t ('\\'); Ten One returnstrtemp; A}
Finally run the program, I click on another window to execute, pop up this animated GIF window, the effect such as:
The GIF image used is generated using the http://preloaders.net/website.
MFC add GIF animations