MFC实现选择文件夹的对话框

由于MFC自带的CFileDiag是只能选择文件的,无法定制只能选择文件夹的对话框。然后当你仅仅需要操作文件夹,批量操作文件时,你需要用WIN32API实现,以下贴出制做该对话框的函数。


void CQQICKView::OnMmm()
{
 // TODO: Add your command handler code here
 CString m_FileDir;
 BROWSEINFO bi;
 ZeroMemory(&bi, sizeof(BROWSEINFO));
 bi.hwndOwner = m_hWnd;
 bi.ulFlags   = BIF_RETURNONLYFSDIRS;
 LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
 BOOL bRet = FALSE;
 TCHAR szFolder[MAX_PATH*2];
 szFolder[0] = _T('\0');
 if (pidl)
 {
  if (SHGetPathFromIDList(pidl, szFolder))  
  bRet = TRUE;
  IMalloc *pMalloc = NULL;
  if (SUCCEEDED(SHGetMalloc(&pMalloc)) && pMalloc)
  
   pMalloc->Free(pidl); 
   pMalloc->Release();
  }
 }
 
 m_FileDir = szFolder;
 TRACE("\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n");
 TRACE(m_FileDir);
 TRACE("\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n");

}

猜你喜欢

转载自blog.csdn.net/qq_34130311/article/details/72518004