#pragma comment(lib, "vfw32.lib")
1初始化
HWDN m_hWndMCIWnd = MCIWndCreate(this->m_hWnd,::AfxGetApp()->m_hInstance,WS_CAPTION,NULL);
MCIWndNew(m_hWndMCIWnd,"waveaudio");
2开始录音
if(MCIWndCanRecord(m_hWndMCIWnd))
{
MCIWndRecord(m_hWndMCIWnd);
}
3停止录音,并保存成wav文件
CFileDialog dlg(FALSE,NULL,NULL,OFN_ALLOWMULTISELECT,"wav File (*.wav)|*.wav");
UINT nRetVal = dlg.DoModal();
if(nRetVal != IDOK) return;
CString strPath = dlg.GetPathName();
strPath += ".wav";
if(MCIWndCanSave(m_hWndMCIWnd))
{
WCHAR swFileName[MAX_PATH];
memset(swFileName, 0, MAX_PATH*sizeof(WCHAR));
LPCTSTR lpszFilePath = strPath.GetBuffer(0);
strPath.ReleaseBuffer();
//如果不是unicode工程
int nLength = MultiByteToWideChar(CP_ACP, 0, lpszFilePath, -1, NULL, 0);
MultiByteToWideChar(CP_ACP, 0, lpszFilePath, -1, swFileName, nLength);
MCIWndSave(m_hWndMCIWnd, (LPCTSTR)swFileName);
}