Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 16: Text-Based Controls Visual C++ and MFC Fundamentals


If you dynamically created the control, you should make sure that the control is destroyed
when its parent also is. This is usually taken care of with the delete operator as done
above. Furthermore, when it comes to the Animator control, after using it, to free the
memory space it space, you should call the CAnimateCtrl::Close() method. Its syntax
is:

BOOL Close();

Practical Learning: Playing a Video File



  1. In the OnInitDialog() event of the dialog class, load the video with the following line
    of code:


BOOL CAnimation1Dlg::OnInitDialog()
{
CDialog::OnInitDialog();

SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here
m_Animateur.Open("C:\\Program Files\\Microsoft Visual
Studio\\Common\\Graphics\\Videos\\FileDel.AVI");

return TRUE; // return TRUE unless you set the focus to a control
}


  1. To close and destroy the animation when the user closes the dialog box, add a
    WM_CLOSE message to the dialog box and implement it as follows:


void CAnimation1Dlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
m_Animator.Stop();
m_Animator.Close();

CDialog::OnClose();
}


  1. Test the application

  2. Return to MSVC

  3. To give the user the ability to suspend video playing, add WM_RBUTTONDOWN
    message to the dialog box and implement it as follows:


void CAnimation1Dlg::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_Animator.Stop();
Free download pdf