如何知道并加载特定文件夹中的所有图像?

Del*_*mer 5 c++ windows-xp c++builder

我有一个应用程序(C++ Builder 6.0)需要知道特定文件夹中的图像总数,然后我必须加载它们:在 ImageList 或 ComboBoxEx 中...或任何其他控件中...

我怎样才能做到这一点?

我知道如何在控件中加载图像,或保存在 TList 或 ImageList 中...但是如何知道目录中有多少个文件,以及如何加载其中的每个图像?

我对我的英语感到抱歉。

Ray*_*yat 3

我昨天使用boost::filesystem库使用 C++ 做了类似的事情。但是,如果您尚未使用 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;
}
Run Code Online (Sandbox Code Playgroud)

但这并不能回答您关于如何实际将路径放入列表框中的问题的部分。