MFC how to load GIF animated pictures

Source: Internet
Author: User

You need to include GIF animations in a project. A version of the Web page in the form of IE browser, JS script, css Others write more cumbersome, another VC project needs to use MFC directly loaded GIF animation. There are many ways to load GIF animations online, most of which are filled with GIF resources, using the Pictureex class load resource file as follows:
The Pictureex picture display class supports images in the following formats: GIF (including animated gif87a and gif89a), JPEG, BMP, WMF, ICO, cur, etc., what I particularly admire is the ability to animate, and easily, It's really cool.
The following is a detailed programming process:

1. New project: Use MFC to create a new dialog-based Gifdemo application in VC6, accept any default options;

2. Insert the document into the project: Copy the Pictureex.h,pictureex.cpp document to the Project Document folder, Project->add to Project->files select Pictureex.h,pictureex.cpp, Insert;

3. Add Picture control : Drag the picture control from the dialog control into the main dialog box and modify its properties : Id:idc_gif, Type:rectangle, the rest accepts the default option. Then add the csatic control variable m_gifpic for idf_gif in Classwiard, and take a look at whether the GifDemoDlg.h is added with # include "PictureEx.h" (added by Classwiard). Then csatic m_gifpic; change to Cpictureex m_gifpic;

4. Load the animation document: The animation document to be loaded into the RES resource folder, and then import it into the project, because MFC only supports the 256BMP document picture, so we want to create a new picture type: "GIF", I am here to put the promotional image of my Site roaring.gif in, and change its ID to: idr_gifroaring.

The detailed process of import (import) GIF animations:
In the ResourceView window, right-click to select the "Import ..." command in the context menu that appears, the "Import Resource" Selection Document dialog box appears, the document type selects "Any document (*. *)", the Open as option is "Auto", Then select the directory where the animation document is located, choose the animated document to load Roaring.gif, and click Import, because the GIF animation type is not the VC default document type, the "Custom Resource Type" dialog box appears, type "GIF", then click OK, And then modify its ID.


5. Add the load code to the appropriate location of the program: here, we add the following code to the Cgifdemodlg::oninitdialog () function:
 
//Todo:add extra initialization here
if (M_gifpic.load (Makeintresource (idr_gifroaring), _t ("Gif")))
M_gifpic.draw ();
However, because our software to write to the hardware device, the file size is strict, several software sharing the same GIF, you must use the dynamic call GIF file loaded into MFC.
looking at the Pictureex class, you will find that there are multiple load functions in the class, one of which can load the file name, but the calling procedure is not simply load, and the GIF animation appears in draw. The experiment was later found to require a static::create before the load file. The source code is as follows:
M_gifpic.create (Null,ws_child | ws_visible | Ss_enhmetafile,crect (50,50,100,100), this,1234);
M_gifpic.load (_t ("c://1.gif"));
M_gifpic.draw ();//
 
OK use Pictureex dynamic loading GIF file complete

MFC how to load GIF animated pictures

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.