CFileDialog打开多个文件失败

CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|

OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,
"Music Files (*.wma;*.mp3)|*.wma;*.mp3||",this);

CString strFilePath;

if(dlg.DoModal() == IDOK)
{
POSITION pos;
int index = 0;
pos = dlg.GetStartPosition();
while(pos)
{
strFilePath = dlg.GetNextPathName(pos);
m_songlist.InsertItem(index,strFilePath);
index++;
}
}

在使用CFileDialog时,打开几个文件,GetStartPosition执行正确,但是打开文件过多的话,GetStartPosition将返还0;


这个是CFileDialog默认文件buffer不够引起的,那么可以在调用DoModal之前手动设置此buffer,修改如下

CString strFilePath;
char* lpFile;
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|
OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,
"Music Files (*.wma;*.mp3)|*.wma;*.mp3||",this);
dlg.m_ofn.nMaxFile = 2566;
lpFile = new char[2566];
dlg.m_ofn.lpstrFile = lpFile;
dlg.m_ofn.lpstrFile[0] = NULL;
dlg.m_ofn.Flags |= OFN_ALLOWMULTISELECT;


if(dlg.DoModal() == IDOK)
{
POSITION pos;
int index = 0;
pos = dlg.GetStartPosition();
while(pos)
{
strFilePath = dlg.GetNextPathName(pos);
m_songlist.InsertItem(index,strFilePath);
index++;
}
}


你可能感兴趣的:(null,buffer)