以下是我写的添加文件的代码:
void CDocumentAdministerDlg::OnAdddocument()
{
static char BASED_CODE szFilter[]
= "所有文件(*.doc;*.ppt;*.pdf)|*.doc;*.ppt;*.pdf|Word 文档(*.doc)|*.doc|PPT 文档(*.ppt)|*.ppt|PDF 文档(*.pdf)|*.pdf||";
static char BASED_CODE szTitle[] = "*.doc;*.ppt;*.pdf";
CFileDialog dlgDir( TRUE,NULL, szTitle ,OFN_HIDEREADONLY |OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT ,szFilter, this );
dlgDir.m_ofn.nFilterIndex = 1;
dlgDir.m_ofn.lpstrTitle = "添加文件";
char szBuffer[1024*10];
memset(szBuffer, 0 , 1024*10);
dlgDir.m_ofn.nMaxFile =1024*10;
dlgDir.m_ofn.lpstrFile=szBuffer;
if (dlgDir.DoModal ()!=IDOK)
{
DWORD dErrorCode=CommDlgExtendedError();
return;
} POSITION pos = dlgDir.GetStartPosition();
CString strFileName, strFilePath;
while (pos != NULL)
{
strFilePath=dlgDir.GetNextPathName(pos);
char szDrive[5], szDir[1024], szName[256], szExt[256];
_splitpath(strFilePath, szDrive, szDir, szName, szExt);
strFileName = szName;
strFileName += szExt;
}
//取得路径
CString strPath;
strPath = m_TreeCtrl.m_strRoot; strPath.TrimRight('\\');
strPath += "\\";
//取得所选路径
HTREEITEM hCurrent = m_TreeCtrl.GetSelectedItem();
CString strDir= m_TreeCtrl.GetItemText(hCurrent);
//为根路径时不能添加
if(strDir == "")
return;
//将文件复制到所选路径下
CopyFile(strFilePath, strPath+strDir+"\\"+strFileName, false); RedrawTreeCtrl();
}此代码只能实现一次一个文件的添加,如果我要选择多个文件一起添加应如何修改?
void CDocumentAdministerDlg::OnAdddocument()
{
static char BASED_CODE szFilter[]
= "所有文件(*.doc;*.ppt;*.pdf)|*.doc;*.ppt;*.pdf|Word 文档(*.doc)|*.doc|PPT 文档(*.ppt)|*.ppt|PDF 文档(*.pdf)|*.pdf||";
static char BASED_CODE szTitle[] = "*.doc;*.ppt;*.pdf";
CFileDialog dlgDir( TRUE,NULL, szTitle ,OFN_HIDEREADONLY |OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT ,szFilter, this );
dlgDir.m_ofn.nFilterIndex = 1;
dlgDir.m_ofn.lpstrTitle = "添加文件";
char szBuffer[1024*10];
memset(szBuffer, 0 , 1024*10);
dlgDir.m_ofn.nMaxFile =1024*10;
dlgDir.m_ofn.lpstrFile=szBuffer;
if (dlgDir.DoModal ()!=IDOK)
{
DWORD dErrorCode=CommDlgExtendedError();
return;
} POSITION pos = dlgDir.GetStartPosition();
CString strFileName, strFilePath;
while (pos != NULL)
{
strFilePath=dlgDir.GetNextPathName(pos);
char szDrive[5], szDir[1024], szName[256], szExt[256];
_splitpath(strFilePath, szDrive, szDir, szName, szExt);
strFileName = szName;
strFileName += szExt;
}
//取得路径
CString strPath;
strPath = m_TreeCtrl.m_strRoot; strPath.TrimRight('\\');
strPath += "\\";
//取得所选路径
HTREEITEM hCurrent = m_TreeCtrl.GetSelectedItem();
CString strDir= m_TreeCtrl.GetItemText(hCurrent);
//为根路径时不能添加
if(strDir == "")
return;
//将文件复制到所选路径下
CopyFile(strFilePath, strPath+strDir+"\\"+strFileName, false); RedrawTreeCtrl();
}此代码只能实现一次一个文件的添加,如果我要选择多个文件一起添加应如何修改?
// 取得路径
到
CopyFile(...);
放在while(pos!=NULL)的循环之内