The Visual C + + development environment provides a custom-drawn function for the control that enables programmers to give full play to their creativity in designing a more beautiful program interface. The so-called AVI button is that every time the mouse from the button to play a button on the tip of the AVI, in many game programs and three-dimensional animation software (such as Motorcycle Kennedy, cool, etc.) are widely used in this AVI button. It makes the user interface of the program very dynamic, but also makes our program at least appear more professional, this example with the help of Visual C + + powerful control self-drawing function to achieve this AVI button principle and implementation. The interface effect after compiling the program is as shown in Figure one:
Figure I, button to play AVI video stream
One, the realization method
To achieve an animated button that can play an AVI video stream, or to take advantage of the overloaded functionality of the control, this book has been introduced in the example: Implementing the XP-style button, which is no longer discussed here, and readers can refer to the example to see the relevant content. This example mainly discusses how to use MFC's CAnimateCtrl animation class to play the video stream in AVI format, the video stream can come from an AVI file, or it can come from resources. The proper use of animated controls in a program makes the interface of the program more vivid.
The MFC CAnimateCtrl class encapsulates an animated control that is created by the Create () member function that is responsible for creating an animated control declared as:
BOOL Create( DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID );
The parameter Dwstyle in a function is a combination of the control styles shown in table One, rect specifies the dimensions of the control, pParentWnd points to the parent window, and NID is the ID of the control. The function returns True if the creation succeeds.
Style |
Meaning |
Acs_center |
Make the animation in the center of the control, and make the animation after opening the control window size and position remain unchanged. If you do not specify this style, the size of the control is automatically adjusted to fit the size of the animation. |
Acs_transparent |
Make the background of the cartoon transparent (do not output cartoon background color). |
Acs_autoplay |
Once the animation has been turned on, repeat. |
Table one, animation control style
In addition to the style in the table, you typically specify Ws_child, ws_visible, and Ws_border window styles for animation controls. For example, to create an animated control that can play automatically, you should specify its style as ws_child| ws_visible| ws_border| Acs_autoplay.
The main member functions of the CAnimateCtrl class include: bool Open (LPCTSTR lpszfilename), bool Open (UINT NID), bool Play (UINT Nfrom, UINT nTo, UINT nrep ), bool Seek (UINT nTo), bool Stop (), bool Close (), and so on.
The open () function above opens the video stream from an AVI file or resource, and if the parameter lpszfilename or NID is null, the system closes the previously opened video stream. The play () function plays the selected video stream, the parameter nfrom specifies the index of the starting frame of the playback, the index value must be less than 65536, and if 0 is played from the beginning. NTO specifies the index of the end frame, its value must be less than 65536, or 1 to the end of the video stream. Nrep is the number of repetitions of playback, if 1 is infinite repeat playback. The Seek () function is used to statically display a frame of a video stream. The parameter nto is the index of the frame, its value must be less than 65536, if 0, the first frame is displayed, and if-1 displays the last frame, the function returns True if it succeeds. The Stop () function is used to stop the animation from playing. The close () function is used to shut down and purge the video stream from memory. All of the above functions are called to return true successfully, or false.
Reader friends in the process of learning to pay attention to, animation control can not play all of the AVI file, only the following conditions to meet the AVI file can be played: 1 avi file must be silent, can not have channels; 2 AVI files must be uncompressed or compressed with RLE algorithm 3) AVI's palette must remain unchanged. In addition, the biggest limitation of an animation control is that it only displays the default color in the system palette, so if you use an animated control to play a 256-color AVI file, the playback effect looks like a 16-color animation, which is not ideal. In short, an animated control can play only some simple, less-colored avi animations. If you want to play a more satisfactory 256-color AVI file, you need to use the MCI interface, this part of the reader friend to see the information.