AVIPlayerDlg.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // AVIPlayerDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "AVIPlayerDlg.h"
  6. #include "vfw.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. #pragma comment(lib, "VFW32.lib")
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CAVIPlayerDlg dialog
  15. CAVIPlayerDlg::CAVIPlayerDlg(CWnd* pParent /*=NULL*/)
  16. : CDialog(CAVIPlayerDlg::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(CAVIPlayerDlg)
  19. m_Path = _T("");
  20. //}}AFX_DATA_INIT
  21. }
  22. void CAVIPlayerDlg::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(CAVIPlayerDlg)
  26. DDX_Control(pDX, IDC_PAUSE, m_Pause);
  27. DDX_Control(pDX, IDC_PLAY, m_Play);
  28. //}}AFX_DATA_MAP
  29. }
  30. BEGIN_MESSAGE_MAP(CAVIPlayerDlg, CDialog)
  31. //{{AFX_MSG_MAP(CAVIPlayerDlg)
  32. ON_BN_CLICKED(IDC_PLAY, OnPlay)
  33. ON_BN_CLICKED(IDC_PAUSE, OnPause)
  34. ON_BN_CLICKED(IDC_STOP, OnStop)
  35. ON_WM_DESTROY()
  36. //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CAVIPlayerDlg message handlers
  40. BOOL CAVIPlayerDlg::OnInitDialog()
  41. {
  42. CDialog::OnInitDialog();
  43. // TODO: Add extra initialization here
  44. m_Video = NULL;
  45. OnPlay();
  46. return TRUE; // return TRUE unless you set the focus to a control
  47. // EXCEPTION: OCX Property Pages should return FALSE
  48. }
  49. void CAVIPlayerDlg::OnPlay()
  50. {
  51. // TODO: Add your control notification handler code here
  52. m_Video = NULL;
  53. if(m_Video == NULL)
  54. {
  55. m_Video = MCIWndCreate(this->GetSafeHwnd(),
  56. AfxGetInstanceHandle(),
  57. WS_CHILD | WS_VISIBLE|MCIWNDF_NOMENU,m_Path);
  58. }
  59. else
  60. {
  61. MCIWndHome(m_Video);
  62. }
  63. MCIWndPlay(m_Video);
  64. Pause = FALSE;
  65. m_Play.EnableWindow(FALSE);
  66. CRect rc,rc2;
  67. ::GetWindowRect (m_Video, &rc);
  68. ScreenToClient(rc);
  69. GetClientRect (&rc2);
  70. int w=rc.Width ();
  71. int h=rc.Height ();
  72. rc.left +=(rc2.Width ()-rc.Width ())/2;
  73. rc.top +=(rc2.Height ()-rc.Height ())/2;
  74. rc.right =rc.left +w;
  75. rc.bottom =rc.top +h;
  76. ::MoveWindow (m_Video, rc.left , rc.top , rc.Width (), rc.Height (), 0);
  77. }
  78. void CAVIPlayerDlg::OnPause()
  79. {
  80. // TODO: Add your control notification handler code here
  81. if(Pause)
  82. {
  83. m_Pause.SetWindowText("Pause");
  84. MCIWndResume(m_Video);
  85. Pause = FALSE;
  86. }
  87. else
  88. {
  89. m_Pause.SetWindowText("UnPause");
  90. MCIWndPause(m_Video);
  91. Pause = TRUE;
  92. }
  93. }
  94. void CAVIPlayerDlg::OnStop()
  95. {
  96. // TODO: Add your control notification handler code here
  97. MCIWndStop(m_Video);
  98. if(m_Video !=NULL)
  99. {
  100. MCIWndDestroy(m_Video);
  101. }
  102. m_Play.EnableWindow(TRUE);
  103. }
  104. void CAVIPlayerDlg::OnDestroy()
  105. {
  106. if(m_Video !=NULL)
  107. {
  108. MCIWndDestroy(m_Video);
  109. }
  110. CDialog::OnDestroy();
  111. }