怎样用VC实现录音机的录音和存储功能 (用对话框做的简单录音机)

xtao123456789 2002-10-26 02:53:51
我现在在做一个录音机 用vc6.0 运行MFC AppWizard[exe]下的对话框模式
我做了3个控件 一个录音一个保存录音一个播放 但是我不知道怎么才能实现录音和保存功能 请各位大虾指教 最好说详细点 谢了
...全文
275 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
NowCan 2002-11-26
  • 打赏
  • 举报
回复
http://vip.6to23.com/NowCan1/tech/wav.htm
freekany2002 2002-11-26
  • 打赏
  • 举报
回复
这里找不到答案吗?来这里试试看!
这里有问必答
http://systemer.51.net/cgi-bin/leoboard.cgi
希望你能在这里找到你满意的答案
PheonixFly 2002-11-26
  • 打赏
  • 举报
回复
Recording with a Waveform-Audio Device
The following example opens a waveform-audio device with a new file, records for the specified time, plays the recording, and prompts the user to save the recording if desired.

// Uses the MCI_OPEN, MCI_RECORD, and MCI_SAVE commands to record and
// save a waveform-audio file. Returns 0L if successful; otherwise,
// it returns an MCI error code.
DWORD recordWAVEFile(DWORD dwMilliSeconds)
{
UINT wDeviceID;
DWORD dwReturn;
MCI_OPEN_PARMS mciOpenParms;
MCI_RECORD_PARMS mciRecordParms;
MCI_SAVE_PARMS mciSaveParms;
MCI_PLAY_PARMS mciPlayParms;

// Open a waveform-audio device with a new file for recording.
mciOpenParms.lpstrDeviceType = "waveaudio";
mciOpenParms.lpstrElementName = "";
if (dwReturn = mciSendCommand(0, MCI_OPEN,
MCI_OPEN_ELEMENT | MCI_OPEN_TYPE,
(DWORD)(LPVOID) &mciOpenParms))
{
// Failed to open device; don't close it, just return error.
return (dwReturn);
}

// The device opened successfully; get the device ID.
wDeviceID = mciOpenParms.wDeviceID;

// Begin recording and record for the specified number of
// milliseconds. Wait for recording to complete before continuing.
// Assume the default time format for the waveform-audio device
// (milliseconds).
mciRecordParms.dwTo = dwMilliSeconds;
if (dwReturn = mciSendCommand(wDeviceID, MCI_RECORD,
MCI_TO | MCI_WAIT, (DWORD)(LPVOID) &mciRecordParms))
{
mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
return (dwReturn);
}

// Play the recording and query user to save the file.
mciPlayParms.dwFrom = 0L;
if (dwReturn = mciSendCommand(wDeviceID, MCI_PLAY,
MCI_FROM | MCI_WAIT, (DWORD)(LPVOID) &mciPlayParms))
{
mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
return (dwReturn);
}
if (MessageBox(hMainWnd, "Do you want to save this recording?",
"", MB_YESNO) == IDNO)
{
mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
return (0L);
}

// Save the recording to a file named TEMPFILE.WAV. Wait for
// the operation to complete before continuing.
mciSaveParms.lpfilename = "tempfile.wav";
if (dwReturn = mciSendCommand(wDeviceID, MCI_SAVE,
MCI_SAVE_FILE | MCI_WAIT, (DWORD)(LPVOID) &mciSaveParms))
{
mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
return (dwReturn);
}

return (0L);
}

上面的程序段实现了用mciSendCommand进行录音的功能,注意MCI_RECORD里面的MCI_WAIT标志,如果在主线程调用里出现该标志,它将租塞主线程。如果使用了MCI_WAIT标志,再开一个工作现程是一个不错的方法,以免主界面出现长时间的停顿。另外,请注意MCI_SAVE里的保存文件名和MCI_OPEN了的打开文件名,并不要求一致。

必须使用MCI_SAVE才能将指定设备录制的内容保存起来,上面的程序段分别实现了MCI_OPEN、MCI_RECORD、MCI_PLAY、MCI_SAVE,你可以根据你的实际情况将各个实现对应不同的响应。
xtao123456789 2002-10-29
  • 打赏
  • 举报
回复
我现在在做一个录音机 用vc6.0 运行MFC AppWizard[exe]下的对话框模式
我做了3个控件 一个录音一个保存录音一个播放 但是我不知道怎么才能实现录音和保存功能 请各位大虾指教 最好说详细点 谢了

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧