打开文件对话框与目录选择对话框

打开文件对话框
const char pszFilter[] = _T("EXE File (*.txt)|*.txt|All Files (*.*)|*.*||");
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
  pszFilter, this);

dlg.m_ofn.lpstrInitialDir = "c:\\WINDOWS\\";  //设置对话框默认呈现的路径

if(dlg.DoModal() == IDOK)
{
CString strFilePath = dlg.GetPathName();
/*如果有多个文件,则
for(POSITION pos = dlg.GetStartPosition(); pos!=NULL; )
  {
   CString strFilePathName = dlg.GetNextPathName(pos);
*/
}

保存文件对话框
const char pszFilter[] = _T("EXE Files (*.txt)|*.txt||");
CFileDialog dlgSave( FALSE,   //FALSE为保存
  _T(".txt"), //自动加上的扩展名
  _T("Output.txt"),  //默认保存的文件名
  OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
  pszFilter, this);



目录选择对话框

 BROWSEINFO bi;
 char szPathName[MAX_PATH];
 char szTitle[] = "选择路径";
 ZeroMemory(&bi, sizeof(BROWSEINFO));
 
 bi.hwndOwner = GetSafeHwnd();
 bi.pszDisplayName = szPathName;
 bi.lpszTitle = szTitle;
 bi.ulFlags = 0x0040 ;
 CString str;
CString strDir;  //选择的目录

 LPITEMIDLIST idl = SHBrowseForFolder(&bi);
 if(idl == NULL)
 {
  strDir= "";
  return;
 }
 
 SHGetPathFromIDList(idl, str.GetBuffer(MAX_PATH * 2));
 str.ReleaseBuffer();
 if(str != "" && str.GetAt(str.GetLength() - 1) != '\\')
  str += "\\";
 strDir = str;

posted on 2006-12-06 16:17 永遇乐 阅读(12957) 评论(0)  编辑 收藏 引用 所属分类: Windows MFC


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2006年12月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

导航

统计

常用链接

留言簿(6)

随笔分类

推荐Blog

友情链接

搜索

最新评论

阅读排行榜