VC中如何使用"瀏覽對話框"

 CString CaaDlg::OnBrowse(void) //打開瀏覽對話框
{
 // TODO: Add your control notification handler code here
 LPMALLOC pMalloc;
 /* Gets the Shell's default allocator */
 if (::SHGetMalloc(&pMalloc) == NOERROR)   //獲得pMalloc
 {       
  BROWSEINFO bi;
  char pszBuffer[MAX_PATH];       
  LPITEMIDLIST pidl;
  // Get help on BROWSEINFO struct - it's got all the bit settings.
  //設定Browse的屬性
  bi.hwndOwner = GetSafeHwnd();       
  bi.pidlRoot = NULL;
  bi.pszDisplayName = pszBuffer;
  bi.lpszTitle = _T( "請選擇保存的位置" );  //
  bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
  bi.lpfn = NULL;       
  bi.lParam = 0;
  // This next call issues the dialog box.
  if ((pidl = ::SHBrowseForFolder(&bi)) != NULL)  //顯示瀏覽窗口  SHBrowseForFolder   
  {
   if (::SHGetPathFromIDList(pidl, pszBuffer)) //把路徑存進pszBuffer中
   {
    // At this point pszBuffer contains the selected path */.
    // Free the PIDL allocated by SHBrowseForFolder.
    pMalloc->Free(pidl);     
    // Release the shell's allocator.  
    pMalloc->Release();
    /************這個有什麼作用嗎?******************
    RECT re;
    re.bottom=100;
    re.left=50;
    re.right=300;
    re.top=50;
    InvalidateRect(&re,TRUE);//清除路徑中的上次的文字
    *******************************************/
    return bi.pszDisplayName;
    //SetDlgItemText(IDC_PATH, bi.pszDisplayName);//填寫路徑名字
   }
   else
    return "";
  }
  else
   return "";
 }
 else
  return "";
}
發佈了30 篇原創文章 · 獲贊 1 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章