用于选择文件夹的对话框

char szPath[MAX_PATH];
 BROWSEINFO bi;
 bi.hwndOwner = this->GetSafeHwnd();
 bi.iImage = 0;
 bi.lParam = 0;
 bi.lpfn = BrowseCallbackProc;
 bi.lpszTitle = "选择文件夹"; 
 bi.pidlRoot  = NULL;
 bi.pszDisplayName = szPath;
 bi.ulFlags =BIF_RETURNONLYFSDIRS ;
 bi.lParam  = (LPARAM)m_strFilePath.GetBuffer(m_strFilePath.GetLength());

 LPITEMIDLIST pItemList = SHBrowseForFolder(&bi);
 if(pItemList)
 {
  if(SHGetPathFromIDList(pItemList, szPath))
  {
   m_strFilePath =szPath; // 文件夹的路径
  }

// 其中需要定义以下回调函数

int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
 if(uMsg==BFFM_SELCHANGED||uMsg==BFFM_INITIALIZED)
 {
  if(uMsg==BFFM_INITIALIZED)
  {
   ::SendMessage(hwnd,BFFM_SETSELECTION,TRUE,
    LPARAM(lpData));
  }
 }
 return 0;
}

 

// 遍历该文件夹中的bmp文件,并获得文件名

 CString strFileName;
 CFileFind finder;
 strFileName = m_strFilePath+_T("//*.bmp");
 //BOOL bWorking = finder.FindFile(_T("*.bmp"));
 BOOL bWorking = finder.FindFile(strFileName);
 while (bWorking)
 {
  bWorking = finder.FindNextFile();
  strFileName = (LPCTSTR)finder.GetFileName();  // bmp文件名
 }

你可能感兴趣的:(用于选择文件夹的对话框)