WaveEditView.cpp
上传用户:samlee1007
上传日期:2007-01-02
资源大小:123k
文件大小:5k
源码类别:

文件操作

开发平台:

Visual C++

  1. // WaveEditView.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "WaveEdit.h"
  5. #include "WaveEditView.h"
  6. #include "WaveEditDoc.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CWaveEditView
  14. IMPLEMENT_DYNCREATE(CWaveEditView, CFormView)
  15. CWaveEditView::CWaveEditView()
  16. : CFormView(CWaveEditView::IDD)
  17. {
  18. m_bPlaying = FALSE;
  19. m_bPaused = FALSE;
  20. m_bStopped = TRUE;
  21. m_bSvrTimerStopped = FALSE;
  22. //{{AFX_DATA_INIT(CWaveEditView)
  23. // NOTE: the ClassWizard will add member initialization here
  24. //}}AFX_DATA_INIT
  25. }
  26. CWaveEditView::~CWaveEditView()
  27. {
  28. }
  29. void CWaveEditView::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CFormView::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(CWaveEditView)
  33. // NOTE: the ClassWizard will add DDX and DDV calls here
  34. //}}AFX_DATA_MAP
  35. }
  36. BEGIN_MESSAGE_MAP(CWaveEditView, CFormView)
  37. //{{AFX_MSG_MAP(CWaveEditView)
  38. ON_COMMAND(ID_PAUSE, OnPause)
  39. ON_UPDATE_COMMAND_UI(ID_PAUSE, OnUpdatePause)
  40. ON_COMMAND(ID_PLAY, OnPlay)
  41. ON_UPDATE_COMMAND_UI(ID_PLAY, OnUpdatePlay)
  42. ON_COMMAND(ID_STOP, OnStop)
  43. ON_UPDATE_COMMAND_UI(ID_STOP, OnUpdateStop)
  44. ON_WM_TIMER()
  45. ON_WM_SETFOCUS()
  46. ON_WM_KILLFOCUS()
  47. ON_WM_CREATE()
  48. ON_WM_PAINT()
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CWaveEditView diagnostics
  53. #ifdef _DEBUG
  54. void CWaveEditView::AssertValid() const
  55. {
  56. CFormView::AssertValid();
  57. }
  58. void CWaveEditView::Dump(CDumpContext& dc) const
  59. {
  60. CFormView::Dump(dc);
  61. }
  62. #endif //_DEBUG
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CWaveEditView message handlers
  65. void CWaveEditView::OnPause() 
  66. {
  67. m_bPaused = !m_bPaused;
  68. if (m_bPaused)
  69. KillTimer(1);
  70. else 
  71. SetTimer(1, 25, NULL);
  72. }
  73. void CWaveEditView::OnUpdatePause(CCmdUI* pCmdUI) 
  74. {
  75. if (!m_bPlaying)
  76. pCmdUI->Enable(FALSE);
  77. else
  78. pCmdUI->SetCheck( m_bPaused);
  79. }
  80. void CWaveEditView::OnPlay() 
  81. {
  82. SetTimer(1, 50, NULL);
  83. m_bPlaying = TRUE;
  84. m_bStopped = FALSE;
  85. }
  86. void CWaveEditView::OnUpdatePlay(CCmdUI* pCmdUI) 
  87. {
  88. pCmdUI->Enable(!m_bPlaying);
  89. }
  90. void CWaveEditView::OnStop() 
  91. {
  92. KillTimer(1);
  93. m_bPlaying = FALSE;
  94. m_bPaused = FALSE;
  95. m_bStopped = TRUE;
  96. m_ptCaretPos.x = rcClient.left;
  97. SetCaretPos(m_ptCaretPos);
  98. }
  99. void CWaveEditView::OnUpdateStop(CCmdUI* pCmdUI) 
  100. {
  101. pCmdUI->Enable(!m_bStopped);
  102. }
  103. void CWaveEditView::OnInitialUpdate() 
  104. {
  105. CFormView::OnInitialUpdate();
  106. SetCursor();
  107. }
  108. void CWaveEditView::OnTimer(UINT nIDEvent) 
  109. {
  110. CWaveEditDoc* pDoc = (CWaveEditDoc*)GetDocument();
  111. ASSERT_VALID(pDoc);
  112. m_ptCaretPos.x = m_ptCaretPos.x + 2;
  113. if (m_ptCaretPos.x  > rcClient.right){
  114. pDoc->m_bSvrTimerStopped = TRUE;
  115. m_ptCaretPos.x = rcClient.left;
  116. m_bStopped = TRUE;
  117. m_bPaused = TRUE;
  118. m_bPlaying = FALSE;
  119. KillTimer(1);
  120. }
  121. SetCaretPos(m_ptCaretPos);
  122. pDoc->IsWaveEnd();
  123. CFormView::OnTimer(nIDEvent);
  124. }
  125. void CWaveEditView::OnSetFocus(CWnd* pNewWnd) 
  126. {
  127. pNewWnd = NULL;
  128. //SetCursor();
  129. }
  130. void CWaveEditView::OnKillFocus(CWnd* pOldWnd) 
  131. {
  132. pOldWnd = NULL; 
  133. //::DestroyCaret();
  134. }
  135. int CWaveEditView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  136. {
  137. if (CFormView::OnCreate(lpCreateStruct) == -1)
  138. return -1;
  139. return 0;
  140. }
  141. void CWaveEditView::OnPaint() 
  142. {
  143. CPaintDC dc(this); // device context for painting
  144. int amp;
  145. DrawBack(&dc);
  146. CPen* pOldPen;
  147. CPen pen (PS_SOLID, 0,  RGB(0,255,0));
  148. pOldPen = dc.SelectObject(&pen);
  149. GetClientRect(rcClient);
  150.  
  151. for(int i = 0; i < rcClient.Width(); ++i){
  152. amp = rand()%(rcClient.Height() /3);
  153. dc.MoveTo (rcClient.left + i, rcClient.top + (rcClient.Height()/2) - amp);
  154. dc.LineTo (rcClient.left + i, rcClient.top + (rcClient.Height()/2) + amp);
  155. }
  156. dc.SelectObject(pOldPen);
  157. // Do not call CFormView::OnPaint() for painting messages
  158. }
  159. void CWaveEditView::DrawBack(CDC* pDC)
  160. {
  161. pDC->SetBkColor(RGB (0,0,0));
  162.     pDC->ExtTextOut (m_ptCaretOrigin.x, m_ptCaretOrigin.y,
  163.         ETO_OPAQUE, rcClient, m_strInputText, NULL);
  164. }
  165. //ONLY gets called by the CLIENT app
  166. void CWaveEditView::SetCursor()
  167. {
  168. GetClientRect(rcClient);
  169. m_ptCaretOrigin.x = rcClient.left;
  170. m_ptCaretOrigin.y = rcClient.top;
  171. m_ptCaretPos = m_ptCaretOrigin;
  172. CreateSolidCaret (max (1, ::GetSystemMetrics (SM_CXBORDER)),
  173. rcClient.bottom - rcClient.top);
  174.     SetCaretPos (m_ptCaretPos);
  175.     ShowCaret ();
  176. }
  177. void CWaveEditView::SetPlay()
  178. {
  179. SetTimer(1,50, NULL);
  180. }
  181. void CWaveEditView::SetPause()
  182. {
  183. KillTimer(1);
  184. //SetCursor();
  185. }
  186. void CWaveEditView::SetStop()
  187. {
  188. KillTimer(1);
  189. SetCursor();
  190. }