The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
CSoundFIleDlg you can listen to a sound file before
opening it, kind of like when choosing Windows' sounds. I wanted to be able to do that
in a program I was writing; it was a timer so
I didn't immediately need the sound, and I found it interesting working out what sound to play
when a selection had been made.
Since I couldn't find the code to do it anywhere I wrote it, I'm not aware if
someone has written any similar code.
How to use the classes provided
Include the following files in your project:
And add the line:
"#include ""SoundFileDlg.rc"" //SoundFileDlg template resource\r\n"
in <YourProject.rc> in the TEXTINCLUDE part, this way whenever the resources
are changed your resource include won't be deleted.
#include SoundFileDlg.rc //SoundFileDlg template resource
In your <res/YourProject.rc2>
just copy the template dialog code from SoundFileDlg.rc
to your resource file. (the SoundFileDlg.rc file only has the template window resource)
IMPORTANT Link the Vfw32.lib Library
The usage is the same as a regular
What's the difference with a normal
The difference is very simple the dialog has a play button and a slider; actually
it's a preview window (
CSoundFileDlg is created, the preview window is created,
(with no file).
CWnd * pWnd = this->GetParent();
int newWidth = winRect.Width()*2/3,margin=20,newHeight=24;
prevWndRect.bottom = winRect.bottom - margin;
prevWndRect.top = prevWndRect.bottom - newHeight;
prevWndRect.left = winRect.left + (winRect.Width()-newWidth)/2;
prevWndRect.right = prevWndRect.left + newWidth;
m_cwndPreview.Create(pWnd,WS_CHILD | MCIWNDF_NOMENU,prevWndRect,"");
When the selected file is changed the file is opened in the prelisten window
CString Path = GetPathName();
This preview it's a very simple class, derivated from
has some of
(CWnd* pParentWnd, DWORD dwStyle, const RECT&
rect, LPCSTR szFile=NULL);
File and Device Management
Open(LPCSTR szFileName, DWORD flags=0);
Tested using VC++ 7 with MFC on Windows XP. Should work fine on other Windows
OSs (95/98/NT/ME/200) also. The Demo File was VC++ 7, converted to VC++6
by the VC++7 to VC++6 project converter by Stephane Rodriguez, I
on VC6 so I don't know if there is any incompatibility, I think it works fine.
Before I wrote this code I thought everything had been written (and maybe it
has), but i didn't find this one anywhere, I think it's not a bad idea, at least
I find it useful. Any suggestions, improvements or bugs detected are welcome.