// PlayeBasicVoiceAudioDlg.cpp : implementation file // #include "stdafx.h" #include "dicwav.h" #include "PlayeBasicVoiceAudioDlg.h" #include "Mmsystem.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CPlayeBasicVoiceAudioDlg dialog CPlayeBasicVoiceAudioDlg::CPlayeBasicVoiceAudioDlg(CWnd* pParent /*=NULL*/) : CDialog(CPlayeBasicVoiceAudioDlg::IDD, pParent) { //{{AFX_DATA_INIT(CPlayeBasicVoiceAudioDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_strInputBasicVoiceAudioFileName.Empty(); m_bInputDICOMFileNameChanged = TRUE; } CPlayeBasicVoiceAudioDlg::~CPlayeBasicVoiceAudioDlg() { if(m_strWaveFileName.GetLength()) { DeleteFile((LPCSTR)m_strWaveFileName); } } void CPlayeBasicVoiceAudioDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPlayeBasicVoiceAudioDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CPlayeBasicVoiceAudioDlg, CDialog) //{{AFX_MSG_MAP(CPlayeBasicVoiceAudioDlg) ON_BN_CLICKED(IDC_BUTTON_BROWSE_BASIC_VOICE, OnButtonBrowseBasicVoice) ON_BN_CLICKED(IDC_BUTTON_PLAY, OnButtonPlay) ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop) ON_WM_CLOSE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPlayeBasicVoiceAudioDlg message handlers void CPlayeBasicVoiceAudioDlg::OnButtonBrowseBasicVoice() { // Get the name of the DICOM Basic Voice Audio File to Play CString strInFileName; strInFileName.Empty(); GetDlgItemText (IDC_INPUT_BASIC_VOICE_AUDIO_FILE, strInFileName); TCHAR szFilters[] =_T ("DICOM Files (*.dic;*.dcm)|*.dic;*.dcm|All files (*.*)|*.*||"); CFileDialog dlg (TRUE, NULL, strInFileName,OFN_HIDEREADONLY |OFN_FILEMUSTEXIST, szFilters); if (dlg.DoModal () == IDOK) { SetDlgItemText (IDC_INPUT_BASIC_VOICE_AUDIO_FILE, dlg.GetPathName ()); m_bInputDICOMFileNameChanged = TRUE; } } void CPlayeBasicVoiceAudioDlg::OnButtonPlay() { CString strInFileName; WIN32_FIND_DATA FindFileData; HANDLE hFind; L_UINT16 uDicomRet; GetDlgItemText (IDC_INPUT_BASIC_VOICE_AUDIO_FILE, strInFileName); if(strInFileName.GetLength() == 0) { AfxMessageBox("Please enter a valid input file name "); return ; } hFind = FindFirstFile(strInFileName, &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { AfxMessageBox("Please enter a valid input file name "); return ; } else { FindClose(hFind); } //Do we need to extract the wave stream from the DICOM file? if(m_bInputDICOMFileNameChanged) { LDicomDS DicomDs; LDicomWaveformGroup AudioWaveformGroup; DicomDs.ResetDS(); // Load the dataset uDicomRet = DicomDs.LoadDS((char * )(LPCSTR)strInFileName,0); if(uDicomRet !=DICOM_SUCCESS) { AfxMessageBox("Failed to load dataset"); return ; } // Do we have any waveforms in the dataset? if(DicomDs.GetWaveformGroupCount() <1) { AfxMessageBox("This dataset has no waveform groups"); return; } // Extract the first waveform group if(DicomDs.GetWaveformGroup(0,&AudioWaveformGroup) != DICOM_SUCCESS) { AfxMessageBox("Couldn't extract waveform group from file."); return; } // Extract the wave stream from the waveform group and save it to disk if(!m_strWaveFileName.GetLength () || (AudioWaveformGroup.SaveAudio((L_CHAR * )(LPCSTR)m_strWaveFileName,0) != DICOM_SUCCESS)) { AfxMessageBox("Couldn't extract wave stream from DICOM file"); return ; } } // Play the wave file if (!PlaySound(m_strWaveFileName, 0, SND_FILENAME | SND_ASYNC)) { AfxMessageBox("Failed to play input wave file."); } } void CPlayeBasicVoiceAudioDlg::OnButtonStop() { // Stop playing PlaySound(0, 0, SND_PURGE); } BOOL CPlayeBasicVoiceAudioDlg::OnInitDialog() { CDialog::OnInitDialog(); L_CHAR szTempDirectory[MAX_PATH]; if(GetTempPath(MAX_PATH,szTempDirectory) != 0) { m_strWaveFileName = szTempDirectory; m_strWaveFileName += "\\"; m_strWaveFileName += WAVE_FILE_NAME; } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CPlayeBasicVoiceAudioDlg::OnClose() { PlaySound(0, 0, SND_PURGE); CDialog::OnClose(); }