return TRUE; // return TRUE unless you set the focus to a control
}
void CMCIWavPlayDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMCIWavPlayDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMCIWavPlayDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMCIWavPlayDlg::OnOpenwav() //打开波形音频文件
{
// TODO: Add your control notification handler code here
CString Filter;
char buf[128];
DWORD dwFlag;
Filter = "波形音频文件(*.WAV)|*.WAV||";
CFileDialog fileDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, Filter);
if (fileDlg.DoModal() ==IDOK) // 显示打开文件的对话框
{
m_strname = fileDlg.GetPathName(); // 获得打开的文件名
dwFlag = m_MyMCIWave.OpenWave(m_strname); // 打开波形音频文件
if (dwFlag)
{
mciGetErrorString(dwFlag, buf, strlen(buf)); // 获取错误信息
AfxMessageBox(buf); // 显示错误信息
}
GetDlgItem(IDC_PLAYWAV)->EnableWindow(TRUE); // 使"播放"按钮有效
m_strstatus = "打开文件:"+m_strname; // 构造信息字符串并显示
CTime m_time;
m_time=CTime::GetCurrentTime(); //获取当前时间日期
CString str=m_time.Format("%H:%M:%S:"); //格式化
str=str+m_strstatus;
m_List.AddString(str);//添加到列表框
m_strSample.Format("%5.3f kHZ", m_MyMCIWave.GetSampleRate()/1000.);//获取采样频率
switch (m_MyMCIWave.GetChannel())//获取声道
{
case 1:
m_strChannel = "单声道";
break;
case 2:
m_strChannel = "立体声";
break;
}
m_strbits.Format("%d位", m_MyMCIWave.GetBitLength());//数据位
m_strtime.Format("%02.2fs",m_MyMCIWave.GetWaveLength()/1000.);//时长
UpdateData(FALSE);//显示信息
}
}
void CMCIWavPlayDlg::OnPlaywav() //播放波形文件
{
if (m_MyMCIWave.PlayWave())
{
AfxMessageBox("播放出错");
return;
}
GetDlgItem(IDC_RECORDWAV)->EnableWindow(FALSE); // 使"录音"按钮操作无效
GetDlgItem(IDC_OPENWAV)->EnableWindow(FALSE); // 使"打开"按钮操作无效
GetDlgItem(IDC_PLAYWAV)->EnableWindow(FALSE); // 使"播放"按钮操作无效
GetDlgItem(IDC_STOPWAV)->EnableWindow(true); // 使"停止"按钮操作生效
m_MyMCIWave.m_bPlaying = TRUE;//设置播放标志
m_strstatus = "正在播放……";//播放状态
CTime m_time;
m_time=CTime::GetCurrentTime(); //获取当前时间
CString str=m_time.Format("%H:%M:%S:"); //格式化
str=str+"开始播放";
m_List.AddString(str);//添加到列表框
UpdateData(FALSE);
}
void CMCIWavPlayDlg::OnRecordwav()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_PLAYWAV)->EnableWindow(FALSE); // 使"播放"按钮操作无效
GetDlgItem(IDC_OPENWAV)->EnableWindow(FALSE); // 使"打开"按钮操作无效
GetDlgItem(IDC_RECORDWAV)->EnableWindow(FALSE); // 使"录音"按钮操作无效
GetDlgItem(IDC_STOPWAV)->EnableWindow(true); // 使"停止"按钮操作生效
m_strstatus = "正在录音……"; // 构造信息字符串并显示
CTime m_time;
m_time=CTime::GetCurrentTime();
CString str=m_time.Format("%H:%M:%S: