MFC另存为和保存对话框:
CString sPath;
TCHAR szFilters[]=_T("All files(*.*)|*.*||");
CFileDialog dlg(nFlag,NULL,_T(m_strTime),OFN_HIDEREADONLY| OFN_OVERWRITEPROMPT,szFilters);
dlg.m_ofn.lpstrInitialDir=_T(
"c:\\"
);
if(IDOK==dlg.DoModal())
{
sPath=dlg.GetPathName();
}
nFlag值为true时,是保存对话框,为false时是另存为对话框,m_strTime为默认文件名字。
MFC弹出选择目录对话框:
LPMALLOC lpMalloc;
if(::SHGetMalloc(&lpMalloc)!=NOERROR)
{
AfxMessageBox("选择下载目录操作出错");
return;
}
char szDisplayName[_MAX_PATH];
char szBuffer[_MAX_PATH];
BROWSEINFO browseInfo;
browseInfo.hwndOwner=this->m_hWnd;
browseInfo.pidlRoot=NULL;
browseInfo.pszDisplayName=szDisplayName;
browseInfo.lpszTitle="请选择下载文件的存储路径";
browseInfo.ulFlags=BIF_RETURNFSANCESTORS|BIF_RETURNONLYFSDIRS;
browseInfo.lpfn=NULL;
browseInfo.lParam=0;
LPITEMIDLIST lpItemIDList;
if((lpItemIDList=::SHBrowseForFolder(&browseInfo))!=NULL)
{
if(::SHGetPathFromIDList(lpItemIDList,szBuffer))
{
if(szBuffer[0]=='\0')
{
AfxMessageBox("Fail to get directory",MB_ICONSTOP|MB_OK);
return;
}
DownFileDirectory=szBuffer;
}
else
{
AfxMessageBox("Fail to get directory!",MB_ICONSTOP|MB_OK);
return;
}
lpMalloc->Free(lpItemIDList);
lpMalloc->Release();
}
CString strMsg;
strMsg.Format("选择目录为:%s",DownFileDirectory);
AfxMessageBox(strMsg);
posted on 2013-01-10 16:25
王海光 阅读(1460)
评论(0) 编辑 收藏 引用 所属分类:
MFC