我有一个应用程序(C++ Builder 6.0)需要知道特定文件夹中的图像总数,然后我必须加载它们:在 ImageList 或 ComboBoxEx 中...或任何其他控件中...
我怎样才能做到这一点?
我知道如何在控件中加载图像,或保存在 TList 或 ImageList 中...但是如何知道目录中有多少个文件,以及如何加载其中的每个图像?
我对我的英语感到抱歉。
我昨天用 C++ 做了类似的事情升压::文件系统 http://www.boost.org/doc/libs/1_41_0/libs/filesystem/doc/index.htm图书馆。但是,如果您尚未使用 boost,我强烈建议您使用 Windows 库。这是我的代码,以防万一您感兴趣:
#include <algorithm>
#include <boost/filesystem.hpp>
#include <set>
namespace fs = boost::filesystem;
typedef std::vector<fs::path> PathVector;
std::auto_ptr<PathVector> ImagesInFolder(const fs::path& folderPath) {
std::set<std::string> targetExtensions;
targetExtensions.insert(".JPG");
targetExtensions.insert(".BMP");
targetExtensions.insert(".GIF");
targetExtensions.insert(".PNG");
std::auto_ptr<PathVector> paths(new PathVector());
fs::directory_iterator end;
for(fs::directory_iterator iter(folderPath); iter != end; ++iter) {
if(!fs::is_regular_file(iter->status())) { continue; }
std::string extension = iter->path().extension();
std::transform(extension.begin(), extension.end(), extension.begin(), ::toupper);
if(targetExtensions.find(extension) == targetExtensions.end()) { continue; }
paths->push_back(iter->path());
}
return paths;
}
但这并不能回答您关于如何实际将路径放入列表框中的问题的部分。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)