FileDialog对话框中,选择多个文件的示例代码片段。
LPCTSTR filters = "Bitmap Files (*.bmp) |*.bmp|Bitmap Config Files (*.txt)|*.txt|All Files (*.*)|*.*||";
// 选项中设置 OFN_ALLOWMULTISELECT
CFileDialog fileDialog(TRUE, NULL, NULL,
OFN_ALLOWMULTISELECT | OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY,
filters);
// 设置OFN属性
const int MAX_FILES = 100;
const int BUFFER_SIZE = (MAX_FILES * (MAX_PATH + 1)) + 1;
char* buffer = (char*)malloc(BUFFER_SIZE);
fileDialog.GetOFN().lpstrFile = buffer;
fileDialog.GetOFN().nMaxFile = MAX_FILES;
if (IDCANCEL == fileDialog.DoModal()) return;
// 遍历取到的每个文件
POSITION position = fileDialog.GetStartPosition();
CString tempFileName;
while (position != NULL) {
tempFileName =fileDialog.GetNextPathName(position);
m_bitmapFiles.Add(tempFileName/*fileDialog.GetNextPathName(position)*/);
}
free(buffer);