WaveEditView.cpp
上传用户:samlee1007
上传日期:2007-01-02
资源大小:123k
文件大小:5k
- // WaveEditView.cpp : implementation file
- //
- #include "stdafx.h"
- #include "WaveEdit.h"
- #include "WaveEditView.h"
- #include "WaveEditDoc.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CWaveEditView
- IMPLEMENT_DYNCREATE(CWaveEditView, CFormView)
- CWaveEditView::CWaveEditView()
- : CFormView(CWaveEditView::IDD)
- {
- m_bPlaying = FALSE;
- m_bPaused = FALSE;
- m_bStopped = TRUE;
- m_bSvrTimerStopped = FALSE;
- //{{AFX_DATA_INIT(CWaveEditView)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- CWaveEditView::~CWaveEditView()
- {
- }
- void CWaveEditView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CWaveEditView)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CWaveEditView, CFormView)
- //{{AFX_MSG_MAP(CWaveEditView)
- ON_COMMAND(ID_PAUSE, OnPause)
- ON_UPDATE_COMMAND_UI(ID_PAUSE, OnUpdatePause)
- ON_COMMAND(ID_PLAY, OnPlay)
- ON_UPDATE_COMMAND_UI(ID_PLAY, OnUpdatePlay)
- ON_COMMAND(ID_STOP, OnStop)
- ON_UPDATE_COMMAND_UI(ID_STOP, OnUpdateStop)
- ON_WM_TIMER()
- ON_WM_SETFOCUS()
- ON_WM_KILLFOCUS()
- ON_WM_CREATE()
- ON_WM_PAINT()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CWaveEditView diagnostics
- #ifdef _DEBUG
- void CWaveEditView::AssertValid() const
- {
- CFormView::AssertValid();
- }
- void CWaveEditView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CWaveEditView message handlers
- void CWaveEditView::OnPause()
- {
- m_bPaused = !m_bPaused;
- if (m_bPaused)
- KillTimer(1);
- else
- SetTimer(1, 25, NULL);
-
- }
- void CWaveEditView::OnUpdatePause(CCmdUI* pCmdUI)
- {
- if (!m_bPlaying)
- pCmdUI->Enable(FALSE);
- else
- pCmdUI->SetCheck( m_bPaused);
-
- }
- void CWaveEditView::OnPlay()
- {
- SetTimer(1, 50, NULL);
- m_bPlaying = TRUE;
- m_bStopped = FALSE;
-
- }
- void CWaveEditView::OnUpdatePlay(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!m_bPlaying);
-
- }
- void CWaveEditView::OnStop()
- {
- KillTimer(1);
- m_bPlaying = FALSE;
- m_bPaused = FALSE;
- m_bStopped = TRUE;
- m_ptCaretPos.x = rcClient.left;
- SetCaretPos(m_ptCaretPos);
- }
- void CWaveEditView::OnUpdateStop(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!m_bStopped);
-
- }
- void CWaveEditView::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
-
- SetCursor();
- }
- void CWaveEditView::OnTimer(UINT nIDEvent)
- {
- CWaveEditDoc* pDoc = (CWaveEditDoc*)GetDocument();
- ASSERT_VALID(pDoc);
- m_ptCaretPos.x = m_ptCaretPos.x + 2;
- if (m_ptCaretPos.x > rcClient.right){
- pDoc->m_bSvrTimerStopped = TRUE;
- m_ptCaretPos.x = rcClient.left;
- m_bStopped = TRUE;
- m_bPaused = TRUE;
- m_bPlaying = FALSE;
- KillTimer(1);
- }
-
- SetCaretPos(m_ptCaretPos);
- pDoc->IsWaveEnd();
-
- CFormView::OnTimer(nIDEvent);
- }
- void CWaveEditView::OnSetFocus(CWnd* pNewWnd)
- {
- pNewWnd = NULL;
- //SetCursor();
-
- }
- void CWaveEditView::OnKillFocus(CWnd* pOldWnd)
- {
- pOldWnd = NULL;
- //::DestroyCaret();
-
- }
- int CWaveEditView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFormView::OnCreate(lpCreateStruct) == -1)
- return -1;
-
-
- return 0;
- }
- void CWaveEditView::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
-
- int amp;
-
- DrawBack(&dc);
-
- CPen* pOldPen;
- CPen pen (PS_SOLID, 0, RGB(0,255,0));
- pOldPen = dc.SelectObject(&pen);
- GetClientRect(rcClient);
-
- for(int i = 0; i < rcClient.Width(); ++i){
-
- amp = rand()%(rcClient.Height() /3);
- dc.MoveTo (rcClient.left + i, rcClient.top + (rcClient.Height()/2) - amp);
- dc.LineTo (rcClient.left + i, rcClient.top + (rcClient.Height()/2) + amp);
- }
-
- dc.SelectObject(pOldPen);
-
- // Do not call CFormView::OnPaint() for painting messages
- }
- void CWaveEditView::DrawBack(CDC* pDC)
- {
-
- pDC->SetBkColor(RGB (0,0,0));
- pDC->ExtTextOut (m_ptCaretOrigin.x, m_ptCaretOrigin.y,
- ETO_OPAQUE, rcClient, m_strInputText, NULL);
-
- }
- //ONLY gets called by the CLIENT app
- void CWaveEditView::SetCursor()
- {
- GetClientRect(rcClient);
- m_ptCaretOrigin.x = rcClient.left;
- m_ptCaretOrigin.y = rcClient.top;
- m_ptCaretPos = m_ptCaretOrigin;
- CreateSolidCaret (max (1, ::GetSystemMetrics (SM_CXBORDER)),
- rcClient.bottom - rcClient.top);
-
- SetCaretPos (m_ptCaretPos);
- ShowCaret ();
-
- }
- void CWaveEditView::SetPlay()
- {
- SetTimer(1,50, NULL);
- }
- void CWaveEditView::SetPause()
- {
- KillTimer(1);
- //SetCursor();
- }
- void CWaveEditView::SetStop()
- {
- KillTimer(1);
- SetCursor();
- }