Adding GIF animations to MFC and ATL projects (Cpictureex,cpitureexwnd)

Source: Internet
Author: User

First, how to use the MFC version of the Cpictureex:

1. Add a static text control or picture control to your dialog box, and Group box can;

2. Change the ID of the control to a name such as Idc_mypicture;

3. Use ClassWizard to add variables to the control. such as: Category-control,variable type-cstatic;

4. Replace CStatic with Cpictureex in the header file of the dialog box (don't forget to add PictureEx.h and PictureEx.cpp to your project, and include "PictureEx.h");

5. Add the following code to OnInitDialog (or any other place you like):

1 if (M_picture.load (_t ("mypicture.gif")))    2 3     M_picture.draw ();   

6. Enjoy your animation:)

You can handle the Cpictureex like a standard cstatic, you can create it manually (in fact, when your project window is not a dialog box, you have to), call Cpictureex::create (), and then call Cpicureex::load () and cpicture::D Raw ().

Ii. adding GIF animations to ATL projects

The ATL version of Cpitureexwnd use is also the above steps, but the 3rd difference is that without ClassWizard help, you have to manually add a Cpictureexwnd type of variable, and add the following code in your WM_ In the InitDialog message handler:

1 hwnd hwnd = GetDlgItem (idc_mypic);    2 3 if (hwnd) {   45  M_wndbanner.subclasswindow (hwnd);   M_wndbanner is a manually added variable    67 }  

After that, you can call Cpictureexwnd::load () and Cpicureexwnd::D Raw (). Of course, you can also directly call Cpictureexwnd::create,cpictureexwnd is just a normal window, this ordinary window of the window program contains some extended functions.

The available interface functions are:

1BOOL Load (...)-loads a GIF and prepares an object for display;2BOOL Draw ()-display GIF or GIF animations;3 voidStop ()-Stop the animation;4 voidUnLoad ()-Stop the animation and release all resources;5 voidSetBkColor (COLORREF)-Set the background color (transparent area);6COLORREF GetBkColor ()-get background color;7BOOL isgif ()-judging whether GIF;8BOOL isanimatedgif ()-judging whether GIF animation;9BOOL isplaying ()-Determines whether the animation is in play;TenSIZE GetSize ()-gets the size of the current graph; One intGetframecount ()-gets the number of frames for the current animation; ABOOL Getpaintrect (RECT *lprect)-gets the current drawing area; -BOOL Setpaintrect (ConstRECT *lprect)-setting the drawing area; - Cpictureex[wnd]::load has three versions of overloaded functions: theBOOL Load (LPCTSTR szfilename);//The argument to this version of the overloaded function is the path to the graph, and the return value is a Boolean value that succeeded.  -BOOL Load (hglobal hglobal, DWORD dwsize);//The parameter for this version is the handle and size of the global memory block allocated by GlobalAlloc using the gmem_movable tag.       This function does not free memory, so remember to use GlobalFree to free up memory.  -BOOL Load (LPCTSTR szresourcename,lpctstr szresourcetype);//This version gets the picture name and the picture type from the resource. For example: -M_picture.load (Makeintresource (Idr_mypic), _t ("Giftype"));

Note: After loading a picture, call Cpictureex[wnd]::D Raw () displays it. If it is an animated GIF, the draw function creates a background thread to play the animation, and if it is a still picture, it will be displayed directly by Oleloadpicture/ipicture. You can call Cpictureex[wnd]::stop () to stop the playback thread at any time. If you want not only to terminate the playback thread, but also to release the resources, use Cpictureex[wnd]::unload (). Note: Cpictureex[wnd]::load automatically calls the Unload () function.

By default, the background is filled with color_3dface (that is, the background color of the dialog box).   If you need to change the background color, you can call Cpictureex[wnd]::setbkcolor (COLORREF) after calling Cpictureex[wnd]::load (). Transferred from: http://blog.csdn.net/yibulianhua/article/details/5624393

Adding GIF animations to MFC and ATL projects (Cpictureex,cpitureexwnd)

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.