MFC簡易操作介紹

 

visual C++新增檔案時在project處點選MFC appWizard即可開 始實做一個屬於自己介面。最主是要修改XXX.Dlg.h

XXX.Dlg.cpp

變數以及使用的函式在XXX.Dlg.h定義,如果程式要使用到一些library,也可在這裡include,而XXX.cpp是介面的實作部份。

 

文字方塊:  
1.Button
 
2.Static Text
 
3. EditBos
 
4.Progress Bar

 

                

 

 

 

 

文字方塊: OnBrowse1() 
{
        // TODO: Add your control notification handler code here
        CFileDialog fileDlg(
                TRUE,
                _T("pcm"),
                0,
                OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,
                _T("pcm Files (*.pcm)|*.pcm|")
                );
        if ( fileDlg.DoModal() == IDOK )
        {
                m_FileName1 = fileDlg.GetFileName();
                m_Path1 = fileDlg.GetPathName();
                UpdateData(FALSE);
        }
 
 
 
        
}
         

 

 

 

 

 

註解

             1. CFileDialog fileDlg:開啟檔案對話盒,TRUE,表讀檔,_T("pcm")表只能開啟副檔名pcm的檔案。

             2. m_FileName1 =fileDlg.GetFileName():取得檔名並存到m_FileName1這變數上,就可在見面上顯現

                出檔名。

 

文字方塊:         // TODO: Add your control notification handler code here
UpdateData();
if ( m_FileName1.GetLength() > 0 )
{
if ( waveOut1.IsPlaying() ) {
if ( !waveOut1.Close() ) {
AfxMessageBox( waveOut1.GetError() );
return;
}
}
monWave1.Load( m_FileName1 );
if ( !monDevice1.IsOutputFormat(monWave1) ) {
AfxMessageBox("Format non support?");
return;}
waveOut1.SetWave(monWave1);
waveOut1.SetDevice(monDevice1);
if ( !waveOut1.Open() ) {
AfxMessageBox( waveOut1.GetError() );
return;}
if ( !waveOut1.Play() ) {
AfxMessageBox( waveOut1.GetError() );
return;}
}

 

  

 

 

 

 

 

註解:

            此部份使用到了從網路上找到音訊處理library內的函式,由於過於複雜在此不多做介紹。

文字方塊: int Counter=0;
 
int taps2;
while (taps2 = fread(inbuf3, sizeof(MONO), TAPS, fptr4 )) {
Counter++;
}
    
m_Progress.SetRange(0, Counter );
m_Progress.SetPos(0);
m_Progress.SetStep(1);
AEC aec;

 

   

 

 

註解:m_Progress.SetRange(0,Counter)設定格數範圍,m_Progress.SetPos(0)呼叫時計數一次,

                    m_Progress.SetStep(1)計數器依次增加一格。               

    

 

ONO inbuf1[TAPS]={0}, inbuf2[TAPS]={0},inbuf3[TAPS]={0}, outbuf[TAPS]={0};

CFileDialog fileDlg(

FALSE,

_T("pcm"),

0,OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,_T("pcm Files (*.pcm)|*.pcm")

);  

if ( fileDlg.DoModal() == IDOK )

{

m_FileName3 = fileDlg.GetFileName();

m_Path3 = fileDlg.GetPathName();

UpdateData(FALSE);                        //開啟存檔對話盒。

    }

 

 FILE *fptr1,*fptr2,*fptr3,*fptr4;

 fptr1=fopen(m_Path1, "rb");

 fptr2=fopen(m_Path2, "rb");

 fptr3=fopen(m_Path3, "wb");////open file

 fptr4=fopen(m_Path2, "rb");

 int Counter=0;

 

 int taps2;

  while (taps2 = fread(inbuf3, sizeof(MONO), TAPS, fptr4 )) {

    Counter++;

    }

   

    m_Progress.SetRange(0, Counter );

    m_Progress.SetPos(0);

    m_Progress.SetStep(1);

  AEC aec;

 

  int taps;

  while (taps = fread(inbuf2, sizeof(MONO), TAPS, fptr2 )) {

     

fread(inbuf1, sizeof(MONO), TAPS, fptr1);

  

 m_Progress.StepIt();

 

for (int i = 0; i < taps; ++i) {

int s0 = inbuf2[i];    /* left channel microphone */

int s1 = inbuf1[i];    /* right channel speaker */

s0 = aec.doAEC(s0, s1);

 

      /* copy back */

 inbuf1[i] = 0;        /* left channel silence */

 outbuf[i] = s0;       /* right channel echo cancelled mic */

    }

 

 fwrite(outbuf, sizeof(MONO), taps, fptr3);

   }

   

  fflush(NULL);

  fclose(fptr1);

  fclose(fptr2);

  fclose(fptr3);

  AfxMessageBox( "AEC complete", MB_OK | MB_ICONINFORMATION );

 

  m_Progress.SetPos(0);   //將進度歸0