WaveEditCtrl.cpp
资源名称:WaveEdit.zip [点击查看]
上传用户:dthg120
上传日期:2007-01-01
资源大小:50k
文件大小:3k
源码类别:
多媒体编程
开发平台:
Visual C++
- // WaveEditCtrl.cpp : implementation file
- //
- #include "stdafx.h"
- #include "WaveEdit.h"
- #include "WaveEditCtrl.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CWaveEditCtrl
- CWaveEditCtrl::CWaveEditCtrl()
- {
- m_bStopped = FALSE;
- m_hCursorArrow = AfxGetApp()->LoadStandardCursor (IDC_ARROW);
- m_hCursorIBeam = AfxGetApp()->LoadStandardCursor (IDC_IBEAM);
- }
- CWaveEditCtrl::~CWaveEditCtrl()
- {
- }
- BEGIN_MESSAGE_MAP(CWaveEditCtrl, CWnd)
- //{{AFX_MSG_MAP(CWaveEditCtrl)
- ON_WM_PAINT()
- ON_WM_SETCURSOR()
- ON_WM_CREATE()
- ON_WM_LBUTTONDOWN()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CWaveEditCtrl message handlers
- int CWaveEditCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- CRect rcClient;
- GetClientRect(rcClient);
- m_ptOrigin.x = rcClient.left;
- m_ptOrigin.y = rcClient.top;
- m_ptCaretPos = m_ptOrigin;
- return 0;
- }
- BOOL CWaveEditCtrl::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
- {
- pContext = NULL;
- static CString className = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW);
- return CWnd::CreateEx(WS_EX_CLIENTEDGE | WS_EX_STATICEDGE,
- className, NULL, dwStyle,
- rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
- pParentWnd->GetSafeHwnd(), (HMENU) nID);
- }
- void CWaveEditCtrl::OnPaint()
- {
- int amp;
- CPaintDC dc(this); // device context for painting
- CPen* pOldPen;
- CPen pen (PS_SOLID, 0, RGB(0,255,0));
- pOldPen = dc.SelectObject(&pen);
- CRect rcClient;
- GetClientRect(rcClient);
- for(int i = 0; i < rcClient.Width(); ++i){
- amp = (rand()% 15)% (rcClient.Height() / 2);
- 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 CWnd::OnPaint() for painting messages
- }
- void CWaveEditCtrl::OnLButtonDown(UINT nFlags, CPoint point)
- {
- nFlags = NULL;
- m_bStopped = TRUE;
- MoveCaret();
- m_ptCaretPos.x = point .x;
- }
- BOOL CWaveEditCtrl::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
- {
- CRect rcClient;
- GetClientRect(rcClient);
- if (nHitTest == HTCLIENT) {
- DWORD dwPos = ::GetMessagePos ();
- CPoint point (LOWORD (dwPos), HIWORD (dwPos));
- ScreenToClient (&point);
- ::SetCursor (rcClient.PtInRect (point) ?
- m_hCursorIBeam : m_hCursorArrow);
- return TRUE;
- }
- return CWnd::OnSetCursor(pWnd, nHitTest, message);
- }
- void CWaveEditCtrl::MoveCaret()
- {
- //Invalidate();
- CRect rcClient;
- GetClientRect(rcClient);
- m_ptCaretPos.x = m_ptCaretPos.x + 1;
- if (m_ptCaretPos.x > rcClient.Width()){
- m_bStopped = TRUE;
- m_ptCaretPos.x = 0;
- }
- SetCaretPos(m_ptCaretPos);
- }
- void CWaveEditCtrl::SetCaret()
- {
- CRect rcClient;
- GetClientRect(rcClient);
- CreateSolidCaret (max (1, ::GetSystemMetrics (SM_CXBORDER)),
- rcClient.bottom - rcClient.top);
- SetCaretPos (m_ptCaretPos);
- ShowCaret ();
- }
- void CWaveEditCtrl::KillCaret()
- {
- HideCaret ();
- m_ptCaretPos = GetCaretPos ();
- ::DestroyCaret ();
- }