Chapter 16: Text-Based Controls Visual C++ and MFC Fundamentals
- Add a (Control) variable for the Animator control and name it m_Animator
15.2.3..Animation Methods.............................................................................
The Animator control is based on the CAnimatorCtrl class. Therefore, if you want to
programmatically create an animation, you must first declare a variable of type, or a
pointer to, CAnimationCtrl. You can do this in the view or the dialog class. After
declaring the variable or pointer, to initialize the object, call its Create() method. Here is
an example:
class CControlsDlg : public CDialog
{
// Construction
public:
CControlsDlg(CWnd* pParent = NULL); // standard constructor
~CControlsDlg();
...
private:
CAnimateCtrl *Player;
};
CControlsDlg::CControlsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CControlsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CControlsDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
Player = new CAnimateCtrl;
}
CControlsDlg::~CControlsDlg()
{
delete Player;
}
...
BOOL CControlsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
RECT Recto = { 5, 5, 360, 360 };
Player->Create(WS_CHILD | WS_VISIBLE |
ACS_TRANSPARENT | ACS_AUTOPLAY,
Recto, this, 0x1884);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
After creating the control, you must provide a video to play. This is done by opening a
video file using the CAnimateCtrl::Open() method. It is overloaded with two versions
as follows: