home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Visual Basic.60 / COMMON / TOOLS / VCM / VCM.MDB / VcmComponentContainer / 02_Cabinet / ANIMCTRL.CPP next >
Encoding:
C/C++ Source or Header  |  1998-05-18  |  4.2 KB  |  161 lines

  1. // animctrl.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "CmnCtrl1.h"
  15. #include "animctrl.h"
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char BASED_CODE THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CAnimateCtrlPage property page
  24.  
  25. CAnimateCtrlPage::CAnimateCtrlPage()
  26.     : CPropertyPage(CAnimateCtrlPage::IDD),
  27.     m_dwStyle(WS_CHILD|WS_VISIBLE|ACS_CENTER)
  28. {
  29.     //{{AFX_DATA_INIT(CAnimateCtrlPage)
  30.     m_cstrFileName = _T("");
  31.     m_bCentered = TRUE;
  32.     m_bTransparent = FALSE;
  33.     m_bAutoplay = FALSE;
  34.     //}}AFX_DATA_INIT
  35.     m_psp.dwFlags &= ~PSP_HASHELP;  // Lose the Help button
  36. }
  37.  
  38. void CAnimateCtrlPage::DoDataExchange(CDataExchange* pDX)
  39. {
  40.     CPropertyPage::DoDataExchange(pDX);
  41.     //{{AFX_DATA_MAP(CAnimateCtrlPage)
  42.     DDX_Check(pDX, IDC_CENTER, m_bCentered);
  43.     DDX_Check(pDX, IDC_TRANSPARENT, m_bTransparent);
  44.     DDX_Check(pDX, IDC_AUTOPLAY, m_bAutoplay);
  45.     DDX_Text(pDX, IDC_EDIT1, m_cstrFileName);
  46.     //}}AFX_DATA_MAP
  47. }
  48.  
  49. BEGIN_MESSAGE_MAP(CAnimateCtrlPage, CPropertyPage)
  50.     //{{AFX_MSG_MAP(CAnimateCtrlPage)
  51.     ON_EN_KILLFOCUS(IDC_EDIT1, OnFileChange)
  52.     ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
  53.     ON_BN_CLICKED(IDC_CENTER, OnCenter)
  54.     ON_BN_CLICKED(IDC_TRANSPARENT, OnTransparent)
  55.     ON_BN_CLICKED(IDC_AUTOPLAY, OnAutoplay)
  56.     ON_BN_CLICKED(IDC_PLAY, OnPlay)
  57.     ON_BN_CLICKED(IDC_STOP, OnStop)
  58.     //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60.  
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CAnimateCtrlPage message handlers
  63. BOOL CAnimateCtrlPage::OnInitDialog()
  64. {
  65.     if(!CPropertyPage::OnInitDialog())
  66.         return FALSE;
  67.  
  68.     // Create animation control inside static frame.
  69.     // This is necessary to avoid having the animation control
  70.     // "overflow" the rectangle assigned to it when the
  71.     // ACS_CENTER style is removed.
  72.  
  73.     CWnd* pFrame = GetDlgItem(IDC_ANIMFRAME);
  74.     pFrame->GetClientRect(&m_rectAnimateCtrl);
  75.     m_AnimateCtrl.Create(m_dwStyle, m_rectAnimateCtrl, pFrame, IDC_ANIMATE);
  76.  
  77.     return TRUE;
  78. }
  79.  
  80. void CAnimateCtrlPage::OnFileChange()
  81. {
  82.     UpdateData();
  83.     CFileStatus filestatus;
  84.     if(CFile::GetStatus(m_cstrFileName, filestatus))
  85.         ApplyChanges();
  86. }
  87.  
  88. void CAnimateCtrlPage::OnBrowse()
  89. {
  90.     CFileDialog dlg( TRUE,_T("AVI"),_T("*.AVI"),
  91.                      OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
  92.                      _T("Animation (*.AVI)|*.AVI|"));
  93.  
  94.     if( dlg.DoModal()==IDOK )
  95.     {
  96.         m_cstrFileName = dlg.GetPathName();
  97.         UpdateData(FALSE);
  98.         ApplyChanges();
  99.     }
  100. }
  101.  
  102. void CAnimateCtrlPage::OnCenter()
  103. {
  104.     UpdateData();
  105.     if( m_bCentered )
  106.         m_dwStyle |= ACS_CENTER;
  107.     else
  108.         m_dwStyle &= ~ACS_CENTER;
  109.     ApplyChanges();
  110. }
  111.  
  112. void CAnimateCtrlPage::OnTransparent()
  113. {
  114.     UpdateData();
  115.     if( m_bTransparent )
  116.         m_dwStyle |= ACS_TRANSPARENT;
  117.     else
  118.         m_dwStyle &= ~ACS_TRANSPARENT;
  119.     ApplyChanges();
  120. }
  121.  
  122. void CAnimateCtrlPage::OnAutoplay()
  123. {
  124.     UpdateData();
  125.     if( m_bAutoplay )
  126.         m_dwStyle |= ACS_AUTOPLAY;
  127.     else
  128.         m_dwStyle &= ~ACS_AUTOPLAY;
  129.     ApplyChanges();
  130. }
  131.  
  132. void CAnimateCtrlPage::OnPlay()
  133. {
  134.     // From frame: 1, To frame: end (0xFFFF, or -1),
  135.     // Play once (1)
  136.     m_AnimateCtrl.Play(0,0xFFFF,1);
  137. }
  138.  
  139. void CAnimateCtrlPage::OnStop()
  140. {
  141.     m_AnimateCtrl.Stop();
  142. }
  143.  
  144. void CAnimateCtrlPage::ApplyChanges()
  145. {
  146.     // Stop any current animation and close the animation file
  147.     m_AnimateCtrl.Stop();
  148.     m_AnimateCtrl.Close();
  149.  
  150.     // Set the new style
  151.     ::SetWindowLong(m_AnimateCtrl.GetSafeHwnd(), GWL_STYLE, m_dwStyle);
  152.     // A call to SetWindowPos forces the window to re-read its style
  153.     m_AnimateCtrl.SetWindowPos(NULL, 0, 0, m_rectAnimateCtrl.Width(), m_rectAnimateCtrl.Height(),
  154.                                SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
  155.  
  156.     m_AnimateCtrl.Open(m_cstrFileName);
  157.     // force repaint of the portion of the property page occupied by the control
  158.     InvalidateRect(&m_rectAnimateCtrl);
  159.     UpdateWindow();
  160. }
  161.