WaveEditorView.cpp
上传用户:dthg120
上传日期:2007-01-01
资源大小:50k
文件大小:4k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. // WaveEditorView.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "WaveEdit.h"
  5. #include "WaveEditorView.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CWaveEditorView
  13. IMPLEMENT_DYNCREATE(CWaveEditorView, CFormView)
  14. CWaveEditorView::CWaveEditorView()
  15. : CFormView(CWaveEditorView::IDD)
  16. {
  17. m_bPlaying = FALSE;
  18. m_bPaused = FALSE;
  19. m_bStopped = TRUE;
  20. //{{AFX_DATA_INIT(CWaveEditorView)
  21. // NOTE: the ClassWizard will add member initialization here
  22. //}}AFX_DATA_INIT
  23. }
  24. CWaveEditorView::~CWaveEditorView()
  25. {
  26. }
  27. void CWaveEditorView::DoDataExchange(CDataExchange* pDX)
  28. {
  29. CFormView::DoDataExchange(pDX);
  30. //{{AFX_DATA_MAP(CWaveEditorView)
  31. // NOTE: the ClassWizard will add DDX and DDV calls here
  32. //}}AFX_DATA_MAP
  33. }
  34. BEGIN_MESSAGE_MAP(CWaveEditorView, CFormView)
  35. //{{AFX_MSG_MAP(CWaveEditorView)
  36. ON_COMMAND(ID_PLAY, OnPlay)
  37. ON_COMMAND(ID_STOP, OnStop)
  38. ON_COMMAND(ID_PAUSE, OnPause)
  39. ON_UPDATE_COMMAND_UI(ID_PAUSE, OnUpdatePause)
  40. ON_UPDATE_COMMAND_UI(ID_PLAY, OnUpdatePlay)
  41. ON_UPDATE_COMMAND_UI(ID_STOP, OnUpdateStop)
  42. ON_WM_CREATE()
  43. ON_WM_SETFOCUS()
  44. ON_WM_KILLFOCUS()
  45. ON_WM_TIMER()
  46. ON_COMMAND(ID_FILE_NEW, OnFileNew)
  47. ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
  48. //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CWaveEditorView diagnostics
  52. #ifdef _DEBUG
  53. void CWaveEditorView::AssertValid() const
  54. {
  55. CFormView::AssertValid();
  56. }
  57. void CWaveEditorView::Dump(CDumpContext& dc) const
  58. {
  59. CFormView::Dump(dc);
  60. }
  61. #endif //_DEBUG
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CWaveEditorView message handlers
  64. int CWaveEditorView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  65. {
  66. if (CFormView::OnCreate(lpCreateStruct) == -1)
  67. return -1;
  68. return 0;
  69. }
  70. void CWaveEditorView::OnPlay() 
  71. {
  72. SetTimer(1, 25, NULL);
  73. m_bPlaying = TRUE;
  74. m_bStopped = FALSE;
  75. }
  76. void CWaveEditorView::OnUpdatePlay(CCmdUI* pCmdUI) 
  77. {
  78. pCmdUI->Enable(!m_bPlaying);
  79. }
  80. void CWaveEditorView::OnStop() 
  81. {
  82. KillTimer(1);
  83. m_WaveEditCtrl.m_ptCaretPos.x = 0;
  84. m_WaveEditCtrl.MoveCaret();
  85. m_bStopped = TRUE;
  86. m_bPlaying = FALSE;
  87. m_bPaused = FALSE;
  88. }
  89. void CWaveEditorView::OnUpdateStop(CCmdUI* pCmdUI) 
  90. {
  91. pCmdUI->Enable(!m_bStopped);
  92. }
  93. void CWaveEditorView::OnPause() 
  94. {
  95. m_bPaused = !m_bPaused;
  96. if (m_bPaused)
  97. KillTimer(1);
  98. else 
  99. SetTimer(1, 25, NULL);
  100. }
  101. void CWaveEditorView::OnUpdatePause(CCmdUI* pCmdUI) 
  102. {
  103. if (!m_bPlaying)
  104. pCmdUI->Enable(FALSE);
  105. else
  106. pCmdUI->SetCheck( m_bPaused);
  107. }
  108. void CWaveEditorView::OnInitialUpdate() 
  109. {
  110. CFormView::OnInitialUpdate();
  111. CRect rect;
  112. GetDlgItem(IDC_WAVE_EDIT)->GetWindowRect(rect);
  113. ScreenToClient(rect);
  114. m_WaveEditCtrl.Create(WS_VISIBLE | WS_CHILD, rect, this, 1000);
  115. }
  116. void CWaveEditorView::OnSetFocus(CWnd* pOldWnd) 
  117. {
  118. pOldWnd = NULL; 
  119. m_WaveEditCtrl.SetCaret();
  120. }
  121. void CWaveEditorView::OnKillFocus(CWnd* pNewWnd) 
  122. {
  123. pNewWnd = NULL;
  124. m_WaveEditCtrl.KillCaret();
  125. }
  126. void CWaveEditorView::OnTimer(UINT nIDEvent) 
  127. {
  128. if (m_WaveEditCtrl.m_bStopped){
  129. KillTimer(1);
  130. m_bPlaying = FALSE;
  131. m_bPaused = FALSE;
  132. m_bStopped = TRUE;
  133. m_WaveEditCtrl.m_bStopped = FALSE;
  134. }
  135. m_WaveEditCtrl.MoveCaret();
  136. CFormView::OnTimer(nIDEvent);
  137. }
  138. void CWaveEditorView::OnFileNew() 
  139. {
  140. // TODO: Add your command handler code here
  141. }
  142. void CWaveEditorView::OnFileOpen() 
  143. {
  144. // TODO: Add your command handler code here
  145. }