MFC 选择目录

本函数封装了一段 Windows API,实现选择目录:

CString select_path()
{
  BROWSEINFO bi = {0};
  bi.lpszTitle = _T("选择目录");
  LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
  if (!pidl) {
    return _T("");
  }
  TCHAR path[MAX_PATH];
  SHGetPathFromIDList(pidl, path);

  IMalloc * imalloc = 0;
  if (SUCCEEDED(SHGetMalloc(&imalloc))) {
    imalloc->Free(pidl);
    imalloc->Release();
  }
  return path;
}

 

posted @ 2017-05-27 10:29  探索者软件  阅读(951)  评论(0编辑  收藏  举报