1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
   | #include <cderr.h>
#include <vector>
 
/**
* \brief Browse button procedure : saves selected songs paths in the playlist
*/
void CPlayTyleDlg::OnBrowseBtn()
{
    const int MaxFileCount = 50;
    const int MaxFilePath = MAX_PATH;
    const int MaxFileBuffer = MaxFileCount * MaxFilePath + 1;
    std::vector < TCHAR> fileNamesBuffer (MaxFileBuffer);	
	static char const *FILTERS = "Music File |*.mp3;*.ogg;*.wav;*.wma||"; //And so on
 
	CFileDialog openDlg(
				    TRUE,
				    NULL,
				    NULL,
	                            OFN_ALLOWMULTISELECT|OFN_EXPLORER|OFN_FILEMUSTEXIST,
			            FILTERS,
				    this
				);
    openDlg.GetOFN().lpstrFile = &(fileNamesBuffer[0]);
    openDlg.GetOFN().nMaxFile = (DWORD) fileNamesBuffer.size();
 
	//Buffer troubles... why ?
	if(openDlg.DoModal() == IDOK)
	{
		POSITION pos = openDlg.GetStartPosition();
 
		do
		{
			m_playlist.Add(openDlg.GetNextPathName(pos));
		
		}while(pos != NULL);
	}
	else if(CommDlgExtendedError() == FNERR_BUFFERTOOSMALL)
	{
		AfxMessageBox(_T("Trapped"));
	}
} | 
Partager