Windows/MFC
다중 파일 선택 OFN_ALLOWMULTISELECT
aucd29
2013. 10. 2. 17:56
[code]CFileDialogEx dlg(TRUE, "파일선택", NULL, OFN_ALLOWMULTISELECT,
"All Files (*.*)|*.*||", this);
// 기본 경로를 설정
dlg.m_ofn.lpstrInitialDir = m_szPathName;
// 여러 파일을 선택하기 위해선 메모리 할당을 해야되어.
DWORD MAXFILE = 1000; //2562 is the max
dlg.m_ofn.nMaxFile = MAXFILE;
char* pc = new char[MAXFILE];
dlg.m_ofn.lpstrFile = pc;
dlg.m_ofn.lpstrFile[0] = NULL;
if( dlg.DoModal()==IDOK )
{
POSITION pos = dlg.GetStartPosition();
int i=0;
m_SelectedFile.DeleteAllItems();
while (pos != NULL)
{
CString strPath = dlg.GetNextPathName(pos);
m_szBackupFile[i] = strPath.Right(strPath.GetLength()-strPath.ReverseFind('\\')-1);
m_SelectedFile.InsertItem(i, m_szBackupFile[i]);
i++;
if(i > 50)
{
AfxMessageBox("50개 이상에 파일을 추가할 수 없습니다.");
break;
}
}
}
delete pc;
pc = NULL;[/code]
"All Files (*.*)|*.*||", this);
// 기본 경로를 설정
dlg.m_ofn.lpstrInitialDir = m_szPathName;
// 여러 파일을 선택하기 위해선 메모리 할당을 해야되어.
DWORD MAXFILE = 1000; //2562 is the max
dlg.m_ofn.nMaxFile = MAXFILE;
char* pc = new char[MAXFILE];
dlg.m_ofn.lpstrFile = pc;
dlg.m_ofn.lpstrFile[0] = NULL;
if( dlg.DoModal()==IDOK )
{
POSITION pos = dlg.GetStartPosition();
int i=0;
m_SelectedFile.DeleteAllItems();
while (pos != NULL)
{
CString strPath = dlg.GetNextPathName(pos);
m_szBackupFile[i] = strPath.Right(strPath.GetLength()-strPath.ReverseFind('\\')-1);
m_SelectedFile.InsertItem(i, m_szBackupFile[i]);
i++;
if(i > 50)
{
AfxMessageBox("50개 이상에 파일을 추가할 수 없습니다.");
break;
}
}
}
delete pc;
pc = NULL;[/code]