MFC 打开文件夹选择框并获取文件夹路径


CString FicowGetDirectory()
{
    BROWSEINFO bi;
    char name[MAX_PATH];
    ZeroMemory(&bi, sizeof(BROWSEINFO));
    bi.hwndOwner = AfxGetMainWnd()->GetSafeHwnd();
    bi.pszDisplayName = name;
    bi.lpszTitle = "选择文件夹目录";
    bi.ulFlags = BIF_RETURNFSANCESTORS;
    LPITEMIDLIST idl = SHBrowseForFolder(&bi);
    if (idl == NULL)
        return "";
    CString strDirectoryPath;
    SHGetPathFromIDList(idl, strDirectoryPath.GetBuffer(MAX_PATH));
    strDirectoryPath.ReleaseBuffer();
    if (strDirectoryPath.IsEmpty())
        return "";
    if (strDirectoryPath.Right(1) != "\\")
        strDirectoryPath += "\\";

    return strDirectoryPath;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM