MFC add GIF animations

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.