如何在列表框中列出指定类型的目录的内容 [英] how to list contents of directory of specified type in listbox

查看:66
本文介绍了如何在列表框中列出指定类型的目录的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在列表框中显示特定类型的文件列表(比如音乐文件)怎么做?



当列表显示在列表框,我选择任何一个项目,它应该打开文件如何使它?

I need to show the list of files of specific type(say music files) in List box how to do this?

when the list is displayed in the list box and i select any one item it should open the file how to make it?

推荐答案

有很多代码示例,您可以使用谷歌找到。

http:/ /www.hassan-ahmad.com/2011/03/c-list-all-the-files-in-directory-recursively/ [ ^ ]

There are a lot of code examples you can find with google.
http://www.hassan-ahmad.com/2011/03/c-list-all-the-files-in-directory-recursively/[^]

Good luck!


参见这里 [ ^ ]来自Microsoft的简单解决方案。
See here[^] for an easy solution from Microsoft.


void CDemoDlg::GetDirList(CString sPath)
{
	WIN32_FIND_DATA FindFileData;
	sTmpPath = sPath;
	sTmpPath += "\\*.*";
	HANDLE hFind = FindFirstFile( sTmpPath, &FindFileData );
	if ( hFind == INVALID_HANDLE_VALUE )
        return;
    else {
		do {
		if ( ( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
		 {
		// if directory:
		if ( strcmp(".", FindFileData.cFileName ) && strcmp("..", FindFileData.cFileName) ) 
		{
		sTmpPath = sPath;
		sTmpPath += "\\";
		sTmpPath += FindFileData.cFileName;
		GetDirList( sTmpPath);
		}
	} 
	else // if file:
	{
	sTmpPath = sPath;
	sTmpPath += "\\";
	sTmpPath += FindFileData.cFileName;

	m_SongsList.AddString(sTmpPath);/* adding path to the list Box*/
					
            }
        } while ( FindNextFile( hFind, &FindFileData) != 0 );
			  FindClose( hFind );
    }
    return;
}













void CDemoDlg::OnLbnSelchangeListSongs()
{
    int sel;
    CString Song;
    sel=m_SongsList.GetCurSel();
    m_SongsList.GetText(sel,Song);
    PlaySound(Song,NULL, SND_FILENAME|SND_ASYNC);/* Play only .wav form music files*/

}


这篇关于如何在列表框中列出指定类型的目录的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆