3rd Tuesday of the month. 7:30PM - C/C++ Group, SPRS
Welcome to the C++ Users Group. This group is a "Special Interest Group" of the ACGNJ devoted to discussing programming languages in general and C, C++, and C++ for Windows programming in particular. Each month a small but hopefully useful program (complete with source code) is presented for discussion.
The object of this application is to play MP3 or WMA files from a Drag and Drop List. Use "Drag and Drop" from Windows Explorer to play any file or group of files. Use "Drag and Drop" with folder names to play all of the files in the folder. The application uses the Microsoft "MCIWnd Window Class". Here are several paragraphs quoted from the Microsoft Help Screens:
The MCIWnd Window class is easy to use. By using a single function, MCIWndCreate your application can create a control that plays any device that uses the media control interface (MCI). These devices include CD audio, waveform-audio, MIDI, and video devices.
Automating playback is also quick and easy. Using only one function and two macros, an application can create an MCIWnd window with the appropriate media device, play the device, and close both the device and the window when the content has finished playing.
Note Some devices play content that is stored in files. Other devices, such as CD audio devices, play content that is stored in another medium. For purposes of clarity, this overview refers to both circumstances as "playing the device."
Microsoft Visual C++ Version 6.0. |
Windows API. |
Dialog Based Applications. |
Timers. |
MCI Windows Class |
Controlling Volume |
Simple Drag and Drop. |
Shuffle Algorithm for List Box |
ListBox handling. |
At the meeting on Tuesday night we will be discussing the utility and the source code.
SAMPLE CODE =========== ///////////////////////////////////////////////////////////////////////////// // Scroll the file name. Land here every 1/2 second or so. #pragma warning( push ) #pragma warning( disable : 4100 ) // unreferenced formal parameter void CDropDlg::OnTimer(UINT nIDEvent) { static int idx=0, count=0; static CString lastsong; static enum stateTAG { PAUSEINIT, PAUSE, SCROLLINIT, SCROLL } state = PAUSEINIT; if (m_Playing == 0) { state = PAUSEINIT; m_CurrentFileShort = DEFAULT_TITLE; } if (lastsong != m_CurrentFileShort) { state = PAUSEINIT; lastsong = m_CurrentFileShort; } if (idx >= m_CurrentFileShort.GetLength()) state = PAUSEINIT; switch (state) { case PAUSEINIT: idx = 0; count = 0; state = PAUSE; break; case PAUSE: if (++count > 5) state = SCROLLINIT; break; case SCROLLINIT: idx = 0; state = SCROLL; break; case SCROLL: if (++idx >= m_CurrentFileShort.GetLength()) state = PAUSEINIT; break; } SetWindowText(m_CurrentFileShort.Mid(idx)); } #pragma warning( pop ) ///////////////////////////////////////////////////////////////////////////// // Shuffle the songs in the list box. (Button Hit) #define REPLACE_STRING(IDX, STR) m_Files.DeleteString(IDX), m_Files.InsertString((IDX), (STR)) void CDropDlg::DoShuffle() // With a name group that decreases { // in size down to nothing, replace CString sLastFile, sRandFile; int i, idxRand; // the last name with a random name. srand( (unsigned)time( NULL ) ); // "Seed" the random number generator. for (i=m_Files.GetCount()-1; i>1; i--) { idxRand = rand() % i; m_Files.GetText(i, sLastFile); // get last value m_Files.GetText(idxRand, sRandFile); // get a random value REPLACE_STRING( i, sRandFile); REPLACE_STRING( idxRand, sLastFile); // swap values } m_Index = -1; // anticipate next bump. if (m_Playing) // jump to the current song. m_Index = m_Files.SelectString(0, m_CurrentFile); }
Available from download page.
December 2005 C/C++ Meeting Random Access Notes ================================================= www.acgnj.org C Users Journal - www.cuj.com www.codeproject.com Dr Dobbs = www.ddj.com www.codeguru.com msdn.microsoft.com www.dslreports.com