• 记录: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;

  • 相关阅读:
    3.10 Go Map哈希表
    3.9 Go Slice切片
    3.8 Go Array数组
    3.7 Go指针
    3.6 Go String型
    3.5 Go布尔型
    3.4 Go字符型
    3.3 Go浮点型
    3.2 Go整数类型
    3.1Go变量
  • 原文地址:https://www.cnblogs.com/flyingfish/p/675455.html
Copyright © 2020-2023  润新知