- MFC - Home
- MFC - Overview
- MFC - Environment Setup
- MFC - VC++ Projects
- MFC - Getting Started
- MFC - Windows Fundamentals
- MFC - Dialog Boxes
- MFC - Windows Resources
- MFC - Property Sheets
- MFC - Windows Layout
- MFC - Controls Management
- MFC - Windows Controls
- MFC - Messages & Events
- MFC - Activex Controls
- MFC - File System
- MFC - Standard I/O
- MFC - Document View
- MFC - Strings
- MFC - Carray
- MFC - Linked Lists
- MFC - Database Classes
- MFC - Serialization
- MFC - Multithreading
- MFC - Internet Programming
- MFC - GDI
- MFC - Libraries
MFC - Animation Control
An animation control is a window that displays an Audio clip in AVI format. An AVI clip is a series of bitmap frames, like a movie. Animation controls can only play simple AVI clips, and they do not support sound. It is represented by the CAnimateCtrl class.
Following is the list of methods in CAnimateCtrl class −
| Sr.No. | Methods & Description |
|---|---|
| 1 |
Close Closes the AVI clip. |
| 2 |
Create Creates an animation control and attaches it to a CAnimateCtrl object. |
| 3 |
CreateEx Creates an animation control with the specified Windows extended styles and attaches it to a CAnimateCtrl object. |
| 4 |
IsPlaying Indicates whether an Audio-Video Interleaved (AVI) clip is playing. |
| 5 |
Open Opens an AVI clip from a file or resource and displays the first frame. |
| 6 |
Play Plays the AVI clip without sound. |
| 7 |
Seek Displays a selected single frame of the AVI clip. |
| 8 |
Stop Stops playing the AVI clip. |
Here is the list of messages mapping for animation control −
| Message | Map entry | Description |
|---|---|---|
| ACN_START | ON_ACN_START ( <id>, <memberFxn> ) | The framework calls this member function when an animation is being started. |
| ACN_STOP | ON_ACN_STOP ( <id>, <memberFxn> ) | The framework calls this member function when an animation stop. |
Let us look into a simple example of animation control.
Step 1 − Create a new MFC dialog based project.
Step 2 − Once the project is created, remove the TODO line and click on Animation Control in Toolbox and draw a rectangle as shown in the following snapshot.
Step 3 − To add a control variable for animation control, right-click and select Add Variable.
Step 4 − Enter the variable name and variable type, which is CAnimateCtrl for animation.
Step 5 − Using the Properties window, set the Border value to False, Set the Auto Play, the Center, and the transparent values to True.
Step 6 − Here we have *.avi file in res folder, which is the default folder for any resources used in the project.
Step 7 − To start the animation, we need to call the Open method CAnimateCtrl class. Add the following line of code in CMFCAnimationDemoDlg::OnInitDialog()
m_animationCtrl.Open(L"res\\copyfile.avi");
Step 8 − Here is the complete implementation of CMFCAnimationDemoDlg::OnInitDialog()
BOOL CMFCAnimationDemoDlg::OnInitDialog(){
CDialogEx::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL){
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty()){
pSysMenu -> AppendMenu(MF_SEPARATOR);
pSysMenu -> AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_animationCtrl.Open(L"res\\copyfile.avi");
return TRUE; // return TRUE unless you set the focus to a control
}
Step 9 − When the above code is compiled and executed, you will see the following output.