16,472
社区成员
![](https://csdnimg.cn/release/cmsfe/public/img/topic.427195d5.png)
![](https://csdnimg.cn/release/cmsfe/public/img/me.40a70ab0.png)
![](https://csdnimg.cn/release/cmsfe/public/img/task.87b52881.png)
![](https://csdnimg.cn/release/cmsfe/public/img/share-circle.3e0b7822.png)
// 打开 waveform audio
mciOpen.dwCallback = 0 ;
mciOpen.wDeviceID = 0 ;
mciOpen.lpstrDeviceType = TEXT ("waveaudio") ;
mciOpen.lpstrElementName = TEXT ("") ;
mciOpen.lpstrAlias = NULL ;
dwError = mciSendCommand (0, MCI_OPEN,
MCI_WAIT | MCI_OPEN_TYPE | MCI_OPEN_ELEMENT,
(DWORD) (LPMCI_OPEN_PARMS) &mciOpen) ;
if (dwError != 0)
{
ShowError (hwnd, dwError) ;
return TRUE ;
}
// 保存device ID
wDeviceID = mciOpen.wDeviceID ;
// 开始录音
mciRecord.dwCallback = (DWORD) hwnd ;
mciRecord.dwFrom = 0 ;
mciRecord.dwTo = 0 ;
mciSendCommand (wDeviceID, MCI_RECORD, MCI_NOTIFY,
(DWORD) (LPMCI_RECORD_PARMS) &mciRecord) ;
bRecording = TRUE ;
return TRUE ;
case IDC_RECORD_END:
// 停止录音
mciGeneric.dwCallback = 0 ;
mciSendCommand (wDeviceID, MCI_STOP, MCI_WAIT,
(DWORD) (LPMCI_GENERIC_PARMS) &mciGeneric) ;
// 保存为 WAV 音频文件
mciSave.dwCallback = 0 ;
mciSave.lpfilename = szFileName ;
mciSendCommand (wDeviceID, MCI_SAVE, MCI_WAIT | MCI_SAVE_FILE,
(DWORD) (LPMCI_SAVE_PARMS) &mciSave) ;
// 关闭wave设备
mciSendCommand (wDeviceID, MCI_CLOSE, MCI_WAIT,
(DWORD) (LPMCI_GENERIC_PARMS) &mciGeneric) ;
bRecording = FALSE ;
return TRUE ;
case IDC_PLAY_BEG:
// 打开waveaudio
mciOpen.dwCallback = 0 ;
mciOpen.wDeviceID = 0 ;
mciOpen.lpstrDeviceType = NULL ;
mciOpen.lpstrElementName = szFileName ;
mciOpen.lpstrAlias = NULL ;
dwError = mciSendCommand (0, MCI_OPEN,
MCI_WAIT | MCI_OPEN_ELEMENT,
(DWORD) (LPMCI_OPEN_PARMS) &mciOpen) ;
if (dwError != 0)
{
ShowError (hwnd, dwError) ;
return TRUE ;
}
// 保存ID
wDeviceID = mciOpen.wDeviceID ;
// 开始播放
mciPlay.dwCallback = (DWORD) hwnd ;
mciPlay.dwFrom = 0 ;
mciPlay.dwTo = 0 ;
mciSendCommand (wDeviceID, MCI_PLAY, MCI_NOTIFY,
(DWORD) (LPMCI_PLAY_PARMS) &mciPlay) ;
bPlaying = TRUE ;
return TRUE ;