weifengzc
weifengzc
2015-07-17 07:50
采纳率: 10%
浏览 2.3k
已采纳

mfc 如何通过checkbox控件选择文件夹路径

我创建一个mfc 工程, 如何通过checkbox控件弹出一个对话框选择文件夹路径,并获取该文件夹的路径。求大神指导

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • oyljerry
    oyljerry 2015-07-17 08:00
    已采纳

    勾上check box后,就调用跳出文件选择对话框

     CString strFilePath;
    TCHAR pszBuffer[_MAX_PATH];
    BROWSEINFO bi;  LPITEMIDLIST pidl;
    bi.hwndOwner = NULL;
    bi.pidlRoot = NULL;
    bi.pszDisplayName = pszBuffer;
    bi.lpszTitle = _T("&NCString strFilePath;
    TCHAR pszBuffer[_MAX_PATH];
    BROWSEINFO bi;  LPITEMIDLIST pidl;
    bi.hwndOwner = NULL;
    bi.pidlRoot = NULL;
    bi.pszDisplayName = pszBuffer;
    bi.lpszTitle = _T("Ñ¡Ôñ²¥³ö±í·¾¶");
    bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
    bi.lpfn = NULL;
    bi.lParam = 0;
    if((pidl = SHBrowseForFolder(&bi)) != NULL)
    {
    if(SHGetPathFromIDList(pidl, pszBuffer))
    {
    CString strTemp(pszBuffer);   strFilePath = strTemp;
    if (strFilePath.GetLength() <= 1) 
    {
    }
    else if (strFilePath.Right(1) != _T("\\"))  
    strFilePath += _T("\\");
    }
    }
    GetDlgItem(IDC_STATIC_PATH)->SetWindowText(strFilePath);tilde;&iexcl;&Ocirc;&ntilde;&sup2;&yen;&sup3;&ouml;±í&Acirc;·&frac34;&para;");
    bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
    bi.lpfn = NULL;
    bi.lParam = 0;
    if((pidl = SHBrowseForFolder(&bi)) != NULL)
    {
    if(SHGetPathFromIDList(pidl, pszBuffer))
    {
    CString strTemp(pszBuffer);   strFilePath = strTemp;
    if (strFilePath.GetLength() <= 1) 
    {
    }
    else if (strFilePath.Right(1) != _T("\\"))  
    strFilePath += _T("\\");
    }
    }
    GetDlgItem(IDC_STATIC_PATH)->SetWindowText(strFilePath);
    
    点赞 评论

相关推荐