static int __stdcall BrowseCtrlCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{ LPCTSTR lpszInitPath = (LPCTSTR)lpData; if (uMsg == BFFM_INITIALIZED && !g_strInitPath.IsEmpty()) { ::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)lpszInitPath); } return 0; } 下面的函數(shù)演示了選擇文件夾的操作,,代碼有點亂,,貼到VC的IDE中就好了 void CLeftView::OnBtnBrowse() { GetDlgItem(IDC_EDIT_PATH)-> GetWindowText(g_strInitPath); LPMALLOC pMalloc; CString strPath; if(SHGetMalloc(&pMalloc) == NOERROR) { BROWSEINFO bInfo; ZeroMemory ( (PVOID) &bInfo,sizeof (BROWSEINFO)); bInfo.hwndOwner = NULL; bInfo.pszDisplayName = strPath.GetBuffer (MAX_PATH); bInfo.lpszTitle = _T( "選擇搜索范圍 "); // 副標題 bInfo.ulFlags = BIF_RETURNONLYFSDIRS|BIF_RETURNFSANCESTORS; // 查找路徑 bInfo.lpfn = BrowseCtrlCallback; // 回調函數(shù) bInfo.lParam = (LPARAM)(LPCTSTR)g_strInitPath; // 回調參數(shù) bInfo.iImage = 0; // 返回選擇路徑圖標 LPITEMIDLIST pidl = ::SHBrowseForFolder(&bInfo); strPath.ReleaseBuffer(); if(pidl != NULL) { BOOL bRtn = ::SHGetPathFromIDList(pidl,g_strInitPath.GetBuffer(MAX_PATH)); g_strInitPath.ReleaseBuffer(); if(bRtn) { GetDlgItem(IDC_EDIT_PATH)-> SetWindowText(g_strInitPath); } pMalloc-> Free(pidl); } pMalloc -> Release(); } } |
|
來自: xue_dong5437 > 《我的圖書館》