各位大家好
我依板上建議到Borland網站上下載了一個錄音程式但RUN後都產生檔名為亂碼
是否存檔程式部分有錯啊我試了很多次都一樣不知可不可請大家幫個忙幫我看看是程式哪出問題囉謝謝 #include
#pragma hdrstop
#include
#include "Unit1.h"
//--------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------
HINSTANCE g_hInstance;
//--------------------------------------------------------------------
HANDLE m_hMCIWnd =NULL;
//--------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
//
// open our MCI window along with the program
//
m_hMCIWnd=MCIWndCreate(Handle,
g_hInstance,
//
// uncomment 'WS_VISIBLE' line to display the MCI window
//
// WS_VISIBLE |
WS_CHILD | WS_OVERLAPPED |
WS_CAPTION|WS_BORDER |
MCIWNDF_RECORD | MCIWNDF_SHOWALL,
NULL );
if ( NULL==m_hMCIWnd ) // error?
{
MessageBox(Handle,"Error Creating MCIWnd Window!",NULL, MB_OK);
return;
}
//
// enable record button
//
Button1->Enabled=true;
Label1->Caption="IDLE";
}
//--------------------------------------------------------------------
__fastcall TForm1::~TForm1(void)
{
//
// close our MCI program as we close the form
//
if ( Button2->Enabled )
Button2Click(NULL); // stop and save file before closing
//
// close our MCI window now
//
MCIWndDestroy(m_hMCIWnd);
}
//--------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//
// start recording
//
// create new .WAV file (internal - not yet on disk)
MCIWndNew(m_hMCIWnd, "waveaudio");
// change the default audio setting (which is 11khz 8bit mono)
// to do this successfully, we need to change all of the following:
// MCI_WAVE_SET_PARMS members: wFormatTag, wBitsPerSample,
// nChannels, nSamplesPerSec, nAvgBytesPerSec, and nBlockAlign
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);
if ( result ) // failed?
{
char buffer[100];
mciGetErrorString(result, buffer, sizeof(buffer));
MessageBox( NULL, buffer, "MCI_WAVE_SET_1", MB_OK);
return;
}
// now we can record at our audio setting
MCIWndRecord(m_hMCIWnd);
//
// set GUI buttons so we know we can stop
//
Button1->Enabled=false;
Button2->Enabled=true;
Label1->Caption="RECORDING";
}
//--------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
//
// stop recording and save as unique local file
//
// generate unique filename from timer
char file[260]="";
wsprintf(file,"audd.wav",GetTickCount()0000L);
// now stop audio and save to disk
MCIWndStop(m_hMCIWnd);
MCIWndSave(m_hMCIWnd,file);
MCIWndClose(m_hMCIWnd);
//
// now set buttons so we know we can stop
//
Button1->Enabled=true;
Button2->Enabled=false;
Label1->Caption="IDLE";
}
//--------------------------------------------------------------------