zoukankan      html  css  js  c++  java
  • VC++ 打开保存文件对话框 目录对话框

    //打开文件对话框
    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;

  • 相关阅读:
    数据集冲突
    苹果如何设计iPad的商业模式
    IT部门应如何制定技术路线图
    关于软件测试
    c#写文件
    正则表达式语法及常用表达式。
    使用Mysql的Replication功能实现数据库同步
    CMMI=大象关冰箱?
    asp.net 中RegularExpressionValidator的bug|IE的bug?
    Singleton 模式的Java和C#的实现方法
  • 原文地址:https://www.cnblogs.com/zhangjun1130/p/1894376.html
Copyright © 2011-2022 走看看