📄 wavedemoview.cpp
字号:
// WaveDemoView.cpp : implementation of
// the CWaveDemoView class
//
#include "stdafx.h"
#include "WaveDemo.h"
#include "WaveDemoDoc.h"
#include "WaveDemoView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWaveDemoView
IMPLEMENT_DYNCREATE(CWaveDemoView, CView)
BEGIN_MESSAGE_MAP(CWaveDemoView, CView)
//{{AFX_MSG_MAP(CWaveDemoView)
ON_COMMAND(ID_SOUNDS_LOADFROMDISK_BOING, OnSoundsLoadfromdisk)
ON_COMMAND(ID_SOUNDS_LOADFROMDISK_CARDS, OnSoundsLoadfromdisk)
ON_COMMAND(ID_SOUNDS_LOADFROMDISK_LASER, OnSoundsLoadfromdisk)
ON_COMMAND(ID_SOUNDS_LOADFROMRESOURCE_ALARM, OnSoundsLoadfromresource)
ON_COMMAND(ID_SOUNDS_LOADFROMRESOURCE_BARK, OnSoundsLoadfromresource)
ON_COMMAND(ID_SOUNDS_LOADFROMRESOURCE_SHOCK, OnSoundsLoadfromresource)
ON_COMMAND(ID_SOUNDS_PLAYFROMDISK_BOING, OnSoundsPlayfromdisk)
ON_COMMAND(ID_SOUNDS_PLAYFROMDISK_CARDS, OnSoundsPlayfromdisk)
ON_COMMAND(ID_SOUNDS_PLAYFROMDISK_LASER, OnSoundsPlayfromdisk)
ON_COMMAND(ID_SOUNDS_PLAYFROMRESOURCE_ALARM, OnSoundsPlayfromresource)
ON_COMMAND(ID_SOUNDS_PLAYFROMRESOURCE_BARK, OnSoundsPlayfromresource)
ON_COMMAND(ID_SOUNDS_PLAYFROMRESOURCE_SHOCK, OnSoundsPlayfromresource)
ON_COMMAND(ID_SOUNDS_PLAYLOADEDSOUND, OnSoundsPlayloadedsound)
ON_UPDATE_COMMAND_UI(ID_SOUNDS_PLAYLOADEDSOUND, OnUpdateSoundsPlayloadedsound)
ON_COMMAND(ID_SOUNDS_STOPSOUND, OnSoundsStopsound)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWaveDemoView construction/destruction
static int nResID[] = { IDR_WAVE1, IDR_WAVE2, IDR_WAVE3 };
CWaveDemoView::CWaveDemoView()
{
}
CWaveDemoView::~CWaveDemoView()
{
}
BOOL CWaveDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CWaveDemoView drawing
void CWaveDemoView::OnDraw(CDC* pDC)
{
CWaveDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
}
/////////////////////////////////////////////////////////////////////////////
// CWaveDemoView diagnostics
#ifdef _DEBUG
void CWaveDemoView::AssertValid() const
{
CView::AssertValid();
}
void CWaveDemoView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CWaveDemoDoc* CWaveDemoView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWaveDemoDoc)));
return (CWaveDemoDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CWaveDemoView message handlers
void CWaveDemoView::OnSoundsLoadfromdisk()
{
// Get the menu ID for this message.
WORD wID = GetCurrentMessage()->wParam;
// Have the CWave object load the .wav
// file from disk for the sound that's
// been selected.
if( wID == ID_SOUNDS_LOADFROMDISK_CARDS )
m_Wave.Load( "Sample1.wav" );
else if( wID == ID_SOUNDS_LOADFROMDISK_BOING )
m_Wave.Load( "Sample2.wav" );
else
m_Wave.Load( "Sample3.wav" );
}
void CWaveDemoView::OnSoundsLoadfromresource()
{
// Get the menu ID for this message.
WORD wID = GetCurrentMessage()->wParam;
// Have the CWave object load the wave
// resource for the sound that's been
// selected.
if( wID == ID_SOUNDS_LOADFROMRESOURCE_BARK )
m_Wave.Load( IDR_WAVE3,
AfxGetInstanceHandle() );
else if( wID == ID_SOUNDS_LOADFROMRESOURCE_SHOCK )
m_Wave.Load( IDR_WAVE2,
AfxGetInstanceHandle() );
else
m_Wave.Load( IDR_WAVE1,
AfxGetInstanceHandle() );
}
void CWaveDemoView::OnSoundsPlayfromdisk()
{
// Get the menu ID for this message.
WORD wID = GetCurrentMessage()->wParam;
// Let them know when we start
// by changing the mouse cursor
// to the hourglass.
BeginWaitCursor();
// Have the CWave object play the .wav
// file from disk for the sound that's
// been selected.
if( wID == ID_SOUNDS_PLAYFROMDISK_CARDS )
m_Wave.PlayFromDisk( "Sample1.wav" );
else if( wID == ID_SOUNDS_PLAYFROMDISK_BOING )
m_Wave.PlayFromDisk( "Sample2.wav" );
else
m_Wave.PlayFromDisk( "Sample3.wav" );
// Change the mouse cursor back to
// it's original state before
// the call to BeginWaitCursor().
EndWaitCursor();
}
void CWaveDemoView::OnSoundsPlayfromresource()
{
// Get the menu ID for this message.
WORD wID = GetCurrentMessage()->wParam;
// Let them know when we start
// by changing the mouse cursor
// to the hourglass.
BeginWaitCursor();
// Have the CWave object play the wave
// resource for the sound that's been
// selected.
if( wID == ID_SOUNDS_PLAYFROMRESOURCE_BARK )
m_Wave.PlayFromRes( IDR_WAVE3,
AfxGetInstanceHandle() );
else if( wID == ID_SOUNDS_PLAYFROMRESOURCE_SHOCK )
m_Wave.PlayFromRes( IDR_WAVE2,
AfxGetInstanceHandle() );
else
m_Wave.PlayFromRes( IDR_WAVE1,
AfxGetInstanceHandle() );
// Change the mouse cursor back to
// it's original state before
// the call to BeginWaitCursor().
EndWaitCursor();
}
void CWaveDemoView::OnSoundsPlayloadedsound()
{
// Let them know when we start
// by changing the mouse cursor
// to the hourglass.
BeginWaitCursor();
// Play the loaded sound.
m_Wave.Play();
// Change the mouse cursor back to
// it's original state before
// the call to BeginWaitCursor().
EndWaitCursor();
}
void CWaveDemoView::OnUpdateSoundsPlayloadedsound(
CCmdUI* pCmdUI)
{
// Enable the menu item if a sound has
// been loaded.
pCmdUI->Enable( m_Wave.IsLoaded() );
}
void CWaveDemoView::OnSoundsStopsound()
{
// Stop the sound that's playing.
m_Wave.Stop();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -