www.pudn.com > CHA07.rar > WAVDWV.CPP


// wavdwv.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "waves.h" 
#include "wave.h" 
#include "wavesdoc.h" 
#include "wavdvw.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char BASED_CODE THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CWaveDataView 
 
IMPLEMENT_DYNCREATE(CWaveDataView, CScrollView) 
 
CWaveDataView::CWaveDataView() 
{ 
} 
 
CWaveDataView::~CWaveDataView() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CWaveDataView, CScrollView) 
    //{{AFX_MSG_MAP(CWaveDataView) 
    ON_COMMAND(ID_FILE_SAVE, OnFileSave) 
    ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs) 
    ON_COMMAND(ID_FILE_PLAY, OnFilePlay) 
    ON_COMMAND(ID_FILE_STOP, OnFileStop) 
	ON_WM_CREATE() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CWaveDataView drawing 
 
void CWaveDataView::OnInitialUpdate() 
{ 
    CScrollView::OnInitialUpdate(); 
 
    CSize sizeTotal; 
    // TODO: calculate the total size of this view 
    sizeTotal.cx = m_iFontWidth * 40;   // Columns 
    sizeTotal.cy = m_iFontHeight * 10;  // Lines 
    SetScrollSizes(MM_TEXT, sizeTotal); 
    ResizeParentToFit(); 
} 
 
void CWaveDataView::At(CDC* pDC, int line, char* fmt, ...) 
{ 
    char buf[256]; 
    // Format the string 
    vsprintf(buf, fmt, (char*)(&fmt+1)); 
    pDC->TextOut(0, 
                 line * m_iFontHeight, 
                 buf, 
                 strlen(buf)); 
} 
 
void CWaveDataView::OnDraw(CDC* pDC) 
{ 
    CWavesDoc* pDoc = GetDocument(); 
    CWave* pWave = pDoc->GetWave(); 
    CFont* pOldFont = pDC->SelectObject(&m_Font); 
    pDC->SetBkColor(::GetSysColor(COLOR_WINDOW)); 
    int line = 0; 
    At(pDC, line++, "Wave format..."); 
    WAVEFORMATEX* pfmt = pWave->GetFormat(); 
    ASSERT(pfmt); 
    switch (pfmt->wFormatTag) { 
    case WAVE_FORMAT_PCM: 
        At(pDC, line++, "Format is PCM"); 
        break; 
    default: 
        At(pDC, line++, "Format is unknown (%u)", pfmt->wFormatTag); 
        break; 
    } 
    At(pDC, line++, "%u channels", pfmt->nChannels); 
    At(pDC, line++, "%lu samples per second", pfmt->nSamplesPerSec); 
    At(pDC, line++, "%lu bytes per second (average)", pfmt->nAvgBytesPerSec); 
    At(pDC, line++, "Block alignment is %u bytes", pfmt->nBlockAlign); 
    if (pfmt->wFormatTag == WAVE_FORMAT_PCM) { 
        PCMWAVEFORMAT* pp = (PCMWAVEFORMAT*) pfmt; 
        At(pDC, line++, "PCM data has %u bits per sample", pp->wBitsPerSample); 
    } 
    At(pDC, line++, "%u samples", pWave->GetNumSamples()); 
 
    pDC->SelectObject(pOldFont); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CWaveDataView message handlers 
 
 
void CWaveDataView::OnFileSave() 
{ 
    AfxMessageBox("Not implemented"); 
} 
 
void CWaveDataView::OnFileSaveAs() 
{ 
    AfxMessageBox("Not implemented"); 
} 
 
void CWaveDataView::OnFilePlay() 
{ 
    CWavesDoc* pDoc = GetDocument(); 
    CWave* pWave = pDoc->GetWave(); 
    ASSERT(pWave); 
    if (!pWave->Play()) { 
        AfxMessageBox("Failed to play"); 
    } 
} 
 
void CWaveDataView::OnFileStop() 
{ 
    CWavesDoc* pDoc = GetDocument(); 
    CWave* pWave = pDoc->GetWave(); 
    ASSERT(pWave); 
    pWave->Stop(); 
} 
 
int CWaveDataView::OnCreate(LPCREATESTRUCT lpCreateStruct)  
{ 
	if (CScrollView::OnCreate(lpCreateStruct) == -1) 
		return -1; 
 
   m_Font.CreateStockObject(ANSI_FIXED_FONT); 
   CDC* pDC = GetDC(); 
   CFont* pOldFont = pDC->SelectObject(&m_Font); 
   TEXTMETRIC tm; 
   pDC->GetTextMetrics(&tm); 
   pDC->SelectObject(pOldFont); 
   m_iFontHeight = tm.tmHeight + tm.tmExternalLeading; 
   m_iFontWidth = tm.tmMaxCharWidth; 
 	 
   return 0; 
}