GDI using MS can greatly simplify the development of graphics programs. In VC6, use GDI to copy the GDI header file, lib file, and gdiplus.dll file, copy the header to the VC's Include directory, copy the lib file into the VC's lib directory, then copy gdiplus.dll to Under the system directory (XPSP2 and 2003 have been brought, do not copy) Ulong_ptr # define ulong_ptr unsigned long * # Endif # Pragma Comment (lib, "gdiplus.lib") # include
Bool isanimatedgif (); // Decision is whether it is a dynamic GIF file long getframetime (); / / Get the length of time void ActivenextFrame () to get the current frame should display; // Activate the next frame to display the frame protected:
Bool testforanimatedgif (); void initialize (); uint m_nframecount; // frame number uint m_nframeposition; // Current frame of the serial number BOOL M_BISINIALIZED; / / Whether to initialize the PropertyItem * m_ppropertyItem; // property item, only to test whether it is dynamic image
}; Implementation class as follows: // file name ImageEx.cppImageEx :: ImageEx (const WCHAR * FileName, BOOL useEmbeddedColorManagement): Image (FileName, useEmbeddedColorManagement) {Initialize (); // initialize m_bIsInitialized = true; TestForAnimatedGIF (); // Check is GIF animation}
Imageex :: ~ imageex () {free (m_ppropertyitem); m_ppropertyItem = null;}
void ImageEx :: Initialize () {m_nFramePosition = 0; m_nFrameCount = 0; m_bIsInitialized = false; m_pPropertyItem = NULL;} BOOL ImageEx :: TestForAnimatedGIF () {UINT count = 0; count = GetFrameDimensionsCount (); // get dimension GUID * pdimensionIDS = new guid [count]; // Assign dimension ID array // get the list of frame dimensions from the Image Object. getframedimensionsList (PDIMENSIIDS, Count); // Get each dimension ID // Get the Number of Frames in the first dimension m_nFrameCount = GetFrameCount (& pDimensionIDs [0]);. // the number of frames to obtain a first dimension // Assume that the image has a property item of type PropertyItemEquipMake // get the size of that property item int nSize =.. GetPropertyItemSize (PropertyTagFrameDelay); // item obtained frame delay // Allocate a buffer to receive the property item m_pPropertyItem = (PropertyItem *) malloc (nSize);. GetPropertyItem (PropertyTagFrameDelay, nSize, m_pPropertyItem); delete pDimensionIDs; return m_nFrameCount> 1; }
Bool imageex :: isanimatedgif () {return m_nframecount> 1;}
Long imageex :: getframetime () {long lpause = ((long *) m_ppropertyitem-> value) [m_nframeposition] * 10; return lpause;}
void ImageEx :: ActiveNextFrame () {if (IsAnimatedGif () == FALSE) return; GUID pageGuid = FrameDimensionTime; SelectActiveFrame (& pageGuid, m_nFramePosition ); if (m_nFramePosition == m_nFrameCount) m_nFramePosition = 0;} class is very simple to use, to Display dynamic pictures should be used to help implement it, and the test can be added to the following member variables in a dialog class: imageEx * m_pimg; // Image RECT M_IMGRECT; // Image Area Uint M_NTIMER; / / Timer dialog The constructor and the destructor are as follows: cimgtestdlg :: cimgtestdlg (cwnd * pparent / * = null * /): cdialog (cdialog (cimgtestdlg :: IDD, pParent) {/ {{AFX_DATA_INIT (CIMGTESTDLG) // Note: The ClassWizard Will Add member initialization here //}} AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp () -> LoadIcon (IDR_MAINFRAME); m_pImg = NULL; m_nTimer = 0;} CImgTestDlg :: ~ CImgTestDlg () { IF (m_pimg! = null) {delete m_pimg; m_pimg = null;} if (m_ntimer! = 0) {killtimer (m_ntimer);}} I will load the picture in a Cancel button function and display it, so when we When you click the CANCEL button, the specified image will be loaded and displayed in our dialog: void customtestdlg :: oncancel () {if (m_pimg! = Null) {return;} m_pimg = new iM Ageex (l "gx033.gif"); m_imgRect.Top = 0; m_imgRect.Right = m_pimg-> getWidth (); m_imgRect.bottom = m_pimg-> getHeight (); if (m_pimg-> IsanimatedGIF ()) {long lFrameTime = m_pImg-> GetFrameTime (); m_nTimer = SetTimer (1, lFrameTime, NULL); if (m_nTimer == 0) {MessageBox ( "Timer Null"); return;}} InvalidateRect (& m_ImgRect, FALSE In order to make the picture not flashing when the picture is refreshed, we only refresh the picture area, so we don't have to use the invalidate () function, so that the second parameter of InvalIDateRectt () must be set to false, otherwise, the same will Flash.