下面的代码支持多选,并且分别解出了文件名,后缀名,以及全路径名...取自己所需吧 CFileDialog cfiledlg(TRUE); char filebuffer[8192];
memset(filebuffer,0,8192);
char filter[64];
//这里不能使用strcpy
memcpy(filter,"tga图片(*.tga)\0*.tga\0所有文件(*.*)\0*.*\0\0",64);
cfiledlg.m_ofn.lpstrFilter = filter;
cfiledlg.m_ofn.nMaxFile = 8192;
cfiledlg.m_ofn.nMaxCustFilter = 64;
cfiledlg.m_ofn.lpstrFile = filebuffer;
cfiledlg.m_ofn.Flags |= OFN_EXPLORER|OFN_ALLOWMULTISELECT;
char ext[4] = "tga";
cfiledlg.m_ofn.lpstrDefExt = ext;
char CurDir[260];
GetCurrentDirectory(260,CurDir);
cfiledlg.DoModal();
POSITION pos;
if(pos = cfiledlg.GetStartPosition())
{
CString cs;
CString history("成功添加下列文件:\n");
bool bFileAdded = false;
while(pos)
{
cs = cfiledlg.GetNextPathName(pos);
if(cs.IsEmpty()) continue;
int dotpos = cs.Find(".");
int lastslash;
int curslash = 0;
curslash = cs.Find("\\",curslash);
while(curslash!=-1)
{
lastslash = curslash;
curslash = cs.Find("\\",curslash + 1);
}
CString suffix; CString filename; if(dotpos != -1)
{
suffix = cs.Right(cs.GetLength() - dotpos);
filename = cs.Mid(lastslash + 1,cs.GetLength()-lastslash-suffix.GetLength() -1);
} if(filename.IsEmpty()) continue; char fname[260];
GetCurrentDirectory(260,fname);
sprintf(fname,"%s\\%s",fname,(LPCSTR)filename);
if(!处理此文件函数())
{
CString errstr;
errstr = "error:" + cs;
AfxMessageBox(errstr);
continue;
}
history += cs;
history +=" \n";
bFileAdded = true;
}
if(bFileAdded)
AfxMessageBox(history);
else
AfxMessageBox("没有文件被添加!");
}
memset(filebuffer,0,8192);
char filter[64];
//这里不能使用strcpy
memcpy(filter,"tga图片(*.tga)\0*.tga\0所有文件(*.*)\0*.*\0\0",64);
cfiledlg.m_ofn.lpstrFilter = filter;
cfiledlg.m_ofn.nMaxFile = 8192;
cfiledlg.m_ofn.nMaxCustFilter = 64;
cfiledlg.m_ofn.lpstrFile = filebuffer;
cfiledlg.m_ofn.Flags |= OFN_EXPLORER|OFN_ALLOWMULTISELECT;
char ext[4] = "tga";
cfiledlg.m_ofn.lpstrDefExt = ext;
char CurDir[260];
GetCurrentDirectory(260,CurDir);
cfiledlg.DoModal();
POSITION pos;
if(pos = cfiledlg.GetStartPosition())
{
CString cs;
CString history("成功添加下列文件:\n");
bool bFileAdded = false;
while(pos)
{
cs = cfiledlg.GetNextPathName(pos);
if(cs.IsEmpty()) continue;
int dotpos = cs.Find(".");
int lastslash;
int curslash = 0;
curslash = cs.Find("\\",curslash);
while(curslash!=-1)
{
lastslash = curslash;
curslash = cs.Find("\\",curslash + 1);
}
CString suffix; CString filename; if(dotpos != -1)
{
suffix = cs.Right(cs.GetLength() - dotpos);
filename = cs.Mid(lastslash + 1,cs.GetLength()-lastslash-suffix.GetLength() -1);
} if(filename.IsEmpty()) continue; char fname[260];
GetCurrentDirectory(260,fname);
sprintf(fname,"%s\\%s",fname,(LPCSTR)filename);
if(!处理此文件函数())
{
CString errstr;
errstr = "error:" + cs;
AfxMessageBox(errstr);
continue;
}
history += cs;
history +=" \n";
bFileAdded = true;
}
if(bFileAdded)
AfxMessageBox(history);
else
AfxMessageBox("没有文件被添加!");
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货