www.pudn.com > vc-network-communication.rar > WaveShow.cpp


//NetTalk 
/*------------------------------------------------------------------------------*\ 
 ============================= 
   模块名称: WaveShow.cpp 
 ============================= 
  
 [版权] 
  
   2000-2002  115软件工厂  版权所有 
                                               
\*------------------------------------------------------------------------------*/ 
#include "WndX.h" 
 
#include "WaveShow.h" 
 
/*------------------------------------------------------------------------------*/ 
CWaveShow::CWaveShow() 
{ 
	//to fit the G729a codec,i set the audio format as below 
	//infact the waveshow support not only this format 
	m_crBg=0x00000000; 
	m_crLine=0x00ffffff; 
	m_hbBg=CreateSolidBrush(m_crBg); 
	m_hpLine=CreatePen(PS_SOLID,1,m_crLine); 
	m_hBmp=0; 
	m_Format.wFormatTag	= WAVE_FORMAT_PCM; 
	m_Format.cbSize		= 0; 
	m_Format.wBitsPerSample=16; 
	m_Format.nSamplesPerSec=8000; 
	m_Format.nChannels=1; 
	m_Format.nAvgBytesPerSec	= m_Format.nSamplesPerSec*(m_Format.wBitsPerSample/8); 
	m_Format.nBlockAlign		= m_Format.nChannels     *(m_Format.wBitsPerSample/8); 
} 
/*------------------------------------------------------------------------------*/ 
CWaveShow::~CWaveShow() 
{ 
	 
} 
/*------------------------------------------------------------------------------*/ 
BOOL CWaveShow::Create(RECT &rc,HWND hParent) 
{ 
	return CWndX::Create(0,0,0,WS_CHILD|WS_VISIBLE,rc,hParent,0); 
} 
/*------------------------------------------------------------------------------*/ 
LRESULT CWaveShow::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam) 
{ 
	switch(uMsg) 
	{ 
	case WM_DESTROY: 
		{ 
			if(m_hBmp) 
				DeleteObject(m_hBmp); 
			if(m_hbBg) 
				DeleteObject(m_hbBg); 
			if(m_hpLine) 
				DeleteObject(m_hpLine); 
			m_hBmp=0; 
			m_hbBg=0; 
			m_hpLine=0; 
		} 
		break; 
	case WM_PAINT: 
		OnPaint(); 
		return TRUE; 
	case WM_TIMER: 
		{ 
			KillTimer(m_hWnd,wParam); 
			HDC hdc=GetDC(m_hWnd); 
			Paint(hdc,0,0); 
			ReleaseDC(m_hWnd,hdc); 
		} 
		break; 
	} 
	return CWndX::WndProc(uMsg,wParam,lParam); 
} 
/*------------------------------------------------------------------------------*/ 
 
BOOL CWaveShow::Paint(HDC hdc,char* buf,unsigned uSize) 
{ 
	BOOL bRet=FALSE; 
	BITMAP bmp; 
	GetObject(m_hBmp,sizeof(bmp),&bmp); 
	CRectX rc; 
	GetClientRect(m_hWnd,&rc); 
	if(m_hBmp) 
	{ 
		 
		if(bmp.bmHeight!=rc.Height()||bmp.bmWidth!=rc.Width()) 
		{ 
			DeleteObject(m_hBmp); 
			m_hBmp=CreateCompatibleBitmap(hdc,rc.Width(),rc.Height()); 
		} 
		 
	} 
	else 
	{ 
		m_hBmp=CreateCompatibleBitmap(hdc,rc.Width(),rc.Height()); 
	} 
	if(buf) 
	{ 
				 
		SetTimer(m_hWnd,1,150,0); 
		switch(m_Format.wBitsPerSample) 
		{ 
		case 8: 
			{ 
				HDC hMemDC=CreateCompatibleDC(hdc); 
				HBITMAP hob=(HBITMAP)SelectObject(hMemDC,m_hBmp); 
				FillRect(hMemDC,&CRectX(0,0,rc.Width(),rc.Height()),m_hbBg); 
				 
				HPEN hop=(HPEN)SelectObject(hMemDC,m_hpLine); 
				int iHeight=rc.Height(); 
				int iWidth=rc.Width(); 
				MoveToEx(hMemDC,-1,iHeight/2,0); 
				if(m_Format.nChannels==1) 
				{ 
					 
					for(int i=0;i