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 (); }