码迷,mamicode.com
首页 > Windows程序 > 详细

windows目录选择 文件选择 文件保存对话框

时间:2015-04-03 18:55:48      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

打开文件对话框

 

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,   _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;

  

windows目录选择 文件选择 文件保存对话框

标签:

原文地址:http://www.cnblogs.com/mycway/p/4390699.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!