在打开文件对话框中全选时iResult总是返回2,看msdn说可能是nMaxFile需要设置,不知道怎么改请高手指教。谢谢!
代码如下:
CFileDialog fDlg(TRUE);
fDlg.m_ofn.lpstrTitle = "Select image file";
fDlg.m_ofn.Flags |= OFN_ALLOWMULTISELECT;
static char BASED_CODE szFilter[] = "BMP (*.bmp)\0*.bmp\0JPEG (*.jpg;*.jpeg)\0*.jpg; *.jpeg\0ICON (*.ico)\0*.ico\0GIF (*.gif)\0*.gif\0Exif (*.exif)\0*.exif\0PNG (*.png)\0*.png\0TIFF (*.tiff)\0*.tiff\0WMF (*.wmf)\0*.wmf\0EMF (*.emf)\0*.emf\0All support format\0*.bmp; *.jpg; *.jpeg; *.ico; *.gif; *.exif; *.png, *.tiff; *.wmf; *.emf\0All Files (*.*)\0*.*\0\0";
fDlg.m_ofn.lpstrFilter = szFilter;
fDlg.m_ofn.nFilterIndex = 10;
int iResult = fDlg.DoModal();
if (IDOK == iResult)
{
POSITION pos;
pos = fDlg.GetStartPosition();
while(pos != NULL)
{
CString strFile;
strFile = fDlg.GetNextPathName(pos);
do something ...
}
}
代码如下:
CFileDialog fDlg(TRUE);
fDlg.m_ofn.lpstrTitle = "Select image file";
fDlg.m_ofn.Flags |= OFN_ALLOWMULTISELECT;
static char BASED_CODE szFilter[] = "BMP (*.bmp)\0*.bmp\0JPEG (*.jpg;*.jpeg)\0*.jpg; *.jpeg\0ICON (*.ico)\0*.ico\0GIF (*.gif)\0*.gif\0Exif (*.exif)\0*.exif\0PNG (*.png)\0*.png\0TIFF (*.tiff)\0*.tiff\0WMF (*.wmf)\0*.wmf\0EMF (*.emf)\0*.emf\0All support format\0*.bmp; *.jpg; *.jpeg; *.ico; *.gif; *.exif; *.png, *.tiff; *.wmf; *.emf\0All Files (*.*)\0*.*\0\0";
fDlg.m_ofn.lpstrFilter = szFilter;
fDlg.m_ofn.nFilterIndex = 10;
int iResult = fDlg.DoModal();
if (IDOK == iResult)
{
POSITION pos;
pos = fDlg.GetStartPosition();
while(pos != NULL)
{
CString strFile;
strFile = fDlg.GetNextPathName(pos);
do something ...
}
}
DWORD MAXFILE = 4000
dlg.m_ofn.nMaxFile = MAXFILE;
char* pc = new char[MAXFILE];
dlg.m_ofn.lpstrFile = pc;
dlg.m_ofn.lpstrFile[0] = NULL; int iReturn = dlg.DoModal();
if(iReturn == IDOK)
{
int nCount = 0;
POSITION pos = dlg.GetStartPosition();
while (pos != NULL)
{
dlg.GetNextPathName(pos);
nCount++;
}
CString str;
str.Format("Successfully opened %d files\n", nCount);
AfxMessageBox(str);
}
else if(iReturn == IDCANCEL)
AfxMessageBox("Cancel"); if(CommDlgExtendedError() == FNERR_BUFFERTOOSMALL)
AfxMessageBox("BUFFERTOOSMALL");
delete []pc;
如果需要进一步的信息,您可以参看:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_cfiledialog.asp以及Q179372等有关信息。
{
// TODO: Add your command handler code here
char szFilter[]="Shape文件(*.shp)|*.shp|所有文件(*.*)|*.*||";
CFileDialog dlg(TRUE,"shp", _T("*.shp"),
OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT,
szFilter,this);
CString strFileNames;
dlg.m_ofn.lpstrFile=strFileNames.GetBuffer(2048);
dlg.m_ofn.nMaxFile=2048;
if(dlg.DoModal()==IDOK)
{
POSITION pos = dlg.GetStartPosition();
while (pos)
{
CString strFilePath=dlg.GetNextPathName(pos);
// find file path name yes or no in the list
//
m_MoProject.AddLayer(strFilePath);
}
RefreshLayerDlg();
RefreshSearchDlg();
}
}