VC:音频函数及MCI实例

1、MessageBeep(UINT uType);

2、sndPlaySound(LPCSTR lpszSound , UINT fuSound);

3、playSound(LPCSTR pszSound,HMODULE hmod,DWORD fdwSound);

4、MCI介绍:

MCIERROR mciSendCommand(

       MCIDEVICEID IDDevice,//接收命令的MCI设备的ID

       UINT uMsg,//发送的命令消息

       DWORD fdwCommand,//命令消息的标志

       DWORD dwParam//命令消息的结构体的地址

);

实例:播放音频

1、新建对话框应用程序,添加播放、暂停按钮;

2、添加变量:    

       BOOL pauseflag;

       MCIDEVICEID m_id;

3、初始化函数中:

       GetDlgItem(IDC_PAUSE)->EnableWindow(FALSE);

4、添加播放、暂停按钮的消息映射,编写函数体:

void CTestDlg::OnStart()

{

       // TODO: Add your control notification handler code here

//

       GetDlgItem(IDC_PAUSE)->EnableWindow(true);

       mciSendCommand(m_id,MCI_CLOSE,0,NULL);

       MCI_OPEN_PARMS m_mci;

       m_mci.lpstrDeviceType="waveaudio";

       m_mci.lpstrElementName="file.wav";

       mciSendCommand(0,MCI_OPEN,MCI_OPEN_TYPE|MCI_OPEN_ELEMENT,(DWORD)(LPVOID)&m_mci);

       m_id=m_mci.wDeviceID;

       MCI_PLAY_PARMS m_message;

       m_message.dwCallback=(long)GetSafeHwnd();

       m_message.dwFrom=0;

       mciSendCommand(m_id,MCI_PLAY,MCI_FROM|MCI_NOTIFY,(DWORD)(LPVOID)&m_message);

 

       //GetDlgItem(IDC_PAUSE)->EnableWindow(false);

}

 

void CTestDlg::OnPause()

{

       // TODO: Add your control notification handler code here

       if(pauseflag!=true)

       {

              pauseflag=true;

              mciSendCommand(m_id,MCI_PAUSE,0,NULL);

              SetDlgItemText(IDC_PAUSE,"继续");

       }

       else

       {

              pauseflag=false;

              mciSendCommand(m_id,MCI_RESUME,0,NULL);

              SetDlgItemText(IDC_PAUSE,"暂停");

       }

}

5、添加MM_MCINOTIFY消息映射。

头文件中:

       //{{AFX_MSG(CTestDlg)

      

       afx_msg LRESULT MciNotify(WPARAM wParam,LPARAM lparam);

       //}}AFX_MSG

消息映射入口中:

BEGIN_MESSAGE_MAP(CTestDlg, CDialog)

       //{{AFX_MSG_MAP(CTestDlg)

       //}}AFX_MSG_MAP

       ON_MESSAGE(MM_MCINOTIFY,MciNotify)

END_MESSAGE_MAP()

 

LRESULT CTestDlg::MciNotify(WPARAM wParam,LPARAM lparam)

{

       GetDlgItem(IDC_PAUSE)->EnableWindow(false);

       return 0;

 

}

你可能感兴趣的:(函数)