VC + + to achieve output GIF to form and display GIF animation method _c language

Source: Internet
Author: User

This article describes VC + + in the form of the display of GIF animation method, which is the main part of the code, in this code, VC + + will use GDI technology to load GIF images, define the GUID array, define pointers, initialize the member variables, release Property objects, release GUIDs and other resources.

The code is as follows:

Load gif file void Coutputgifdlg::onbrowse () {CFileDialog Fldlg (TRUE, "", "", Ofn_hidereadonly | Ofn_overwriteprompt, "gif|*.gif;| |");
 /Definition File Open dialog box if (fldlg.domodal () = = Idok) {CString sztext;
 Sztext = Fldlg.getpathname ();
 M_filename.setwindowtext (Sztext); M_pbmp = Bitmap::fromfile (sztext.allocsysstring ());
 Load GIF image sztext.releasebuffer (); M_ncount = M_pbmp->getframedimensionscount (); Gets the frame dimension GUID *pguids = new Guid[m_ncount]; Defines a GUID array m_pbmp->getframedimensionslist (PGUIDS,M_NCOUNT); Gets the GUID M_framecount = M_pbmp->getframecount (pguids) of the image frame; Gets the GIF frame number UINT nsize; Defines an integer variable m_ncount = 0; Initialize the member variable m_pbmp->getpropertysize (&nsize, &m_ndelay); Gets the property size PropertyItem *pitem = NULL; Define attribute pointer Pitem = (propertyitem*) malloc (nsize); Allocate the appropriate space for the property pointer M_pbmp->getallpropertyitems (nsize, M_ndelay, pitem); Get property Information M_ndelay = ((long*) pitem->value) [0 ]; Gets the delay free (pitem) of the first frame; Releases the Property object delete [] pguids; Release GUID m_nindex = 0;
 Initialize member variable KillTimer (1);SetTimer (1, MB, NULL); } void Coutputgifdlg::ontimer (UINT nidevent) {guid = Framedimensiontime;//define a GUID cdc* PDC = GetDC ();//Get window Set
 Standby context//define a memory canvas CMEMDC DC (PDC, CRect (M, M_pbmp->getwidth () +20, M_pbmp->getheight () +50)); Graphics gh (DC.M_HDC); Define an Image object//To draw the image GH into the device context.
 DrawImage (m_pbmp, 0, 0, m_pbmp->getwidth (), M_pbmp->getheight ()); M_pbmp->selectactiveframe (&guid, m_nindex++)//Set the next frame if (M_nindex = = M_framecount)//Determine if the current frame is the tail frame m_nindex = 0;
Sets the current frame to the first frame Cdialog::ontimer (nidevent);
 } void Coutputgifdlg::oncancel () {if (m_pbmp!= NULL) {delete m_pbmp;
 M_pbmp = NULL;
} cdialog::oncancel (); }

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: 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.