您的位置:首页 > 其它

MFC文件对话框不能选太多文件的解决方法

2017-08-02 17:37 204 查看
MFC文件对话框不能选太多文件的解决方法如下:

void CxxxDlg::OnBnClickedButtonX()
{
// TODO: Add your control notification handler code here
CString strFileName;
CFileDialog dlg(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT|OFN_FILEMUSTEXIST,
"图片文件(*.jpg)|*.jpg|文本文件(*.txt)|*.txt|All(*.*)|*.*|", this);

// 自定义用于接收文件名的缓冲区的大小。必须重新分配缓冲区,否则无法同时选择太多的文件。
CONST DWORD nMaxFile = 1024*1024;

char* pbFileNameBuf = new char[nMaxFile];
if ( NULL == pbFileNameBuf )
{
return ; // E_OUTOFMEMORY
}
memset(pbFileNameBuf, 0, nMaxFile);

dlg.m_pOFN->lpstrFile = pbFileNameBuf;
dlg.m_pOFN->nMaxFile = nMaxFile;

if ( IDOK == dlg.DoModal() )
{
POSITION pos = dlg.GetStartPosition();
while ( NULL != pos )
{
strFileName = dlg.GetNextPathName(pos);

//在调试信息区依次输出所选的每一个文件名
OutputDebugString(strFileName);
OutputDebugString("/r/n");
}
}

if ( NULL != pbFileNameBuf )
{
delete[] pbFileNameBuf;
pbFileNameBuf = NULL;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: