MFCフォルダを開いて画像を読み込む

1339 ワード

主にCFIleDialogクラスを使用して実現します.
//void ReadSource()
void ReadSource()
{
	CFileDialog ccFileDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT, 
		_T("Image files(*.png; *.jpg)|*.png;*.jpg|All files(*.*)|*.*||"), NULL);
	if (ccFileDlg.DoModal() == IDOK)
	{
		CString strPathName = ccFileDlg.GetPathName();
		CString strDir = strPathName.Left(strPathName.ReverseFind('\\'));
		ReadFile(strDir))
		
	}
}

//void ReadFile(const CString& strPath)
bool ReadFile(const CString& strPath)
{
	CFileFind ccFileFind;
	CString strTemp = strPath;
	CString strDir = strPath + _T("\\") + _T("*.*");
	CString strFile;

	BOOL bFind = ccFileFind.FindFile(strDir);
	while (bFind)
	{
		bFind = ccFileFind.FindNextFile();
		if (ccFileFind.IsDots())
		{
			//    ".",    
			continue;
		}
		else if (ccFileFind.IsDirectory())
		{
			//      ,     
			strFile = ccFileFind.GetFileName();
			strTemp = strTemp + _T("\\") + strFile;
			this->ReadFile(strTemp);
		}
		else
		{
			//        ,   
			//strFile = ccFileFind.GetFileName();
			strFile = ccFileFind.GetFilePath();	
			m_vecResDirData.push_back(str);  // std::vector<CString> m_vecResDirData
		}
	}
	ccFileFind.Close();
	return true;
}