BCB里用MCI实现简单的录音功能

BCB里用MCI实现简单的录音功能(摘录自BCB Demo)

代码相当简单:

  HANDLE m_hMCIWnd=MCIWndCreate(Handle,
                         HInstance,
                         WS_CHILD | WS_OVERLAPPED | WS_CAPTION | WS_BORDER |
                         MCIWNDF_RECORD | MCIWNDF_SHOWALL,
                         NULL );
      
  MCIWndNew(m_hMCIWnd, "waveaudio");

  MCI_WAVE_SET_PARMS set_parms;
 
  set_parms.wFormatTag      = WAVE_FORMAT_PCM;
  set_parms.wBitsPerSample  = 16;
  set_parms.nChannels       = 1;
  set_parms.nBlockAlign     = (set_parms.nChannels*set_parms.wBitsPerSample)/8;
  set_parms.nSamplesPerSec  = 44100;
  set_parms.nAvgBytesPerSec = ((set_parms.wBitsPerSample) *
                                set_parms.nChannels *
                                set_parms.nSamplesPerSec)/8;

  // now send the format changes with MCI_SET
  int deviceID=MCIWndGetDeviceID(m_hMCIWnd);
  int result = mciSendCommand( deviceID, MCI_SET,
                               MCI_WAIT
                             | MCI_WAVE_SET_FORMATTAG
                             | MCI_WAVE_SET_BITSPERSAMPLE
                             | MCI_WAVE_SET_CHANNELS
                             | MCI_WAVE_SET_SAMPLESPERSEC
                             | MCI_WAVE_SET_AVGBYTESPERSEC
                             | MCI_WAVE_SET_BLOCKALIGN,
                               (DWORD)(LPVOID)&set_parms);

  MCIWndRecord(m_hMCIWnd);  //开始录制

  ShowMessage("录音中...");

  MCIWndStop(m_hMCIWnd);  //录制完毕
  MCIWndSave(m_hMCIWnd,L"abc.wav");   //保存
  MCIWndClose(m_hMCIWnd);

  MCIWndDestroy(m_hMCIWnd);
 
 头文件:#include <vfw.h>

你可能感兴趣的:(null,border)