OnBTGetPath() {
char.zPathBuf[MAX_PATH];
BROWSEINFO bi;
bi.hwndOwner = m_hWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = szPathBuf; //存放路徑的buffer
bi.lpszTitle = "選擇目錄:"; //對話框標題
bi.ulFlags = 0 ;
bi.lpfn = NULL ;
bi.lParam = 0 ; //顯示瀏覽資料夾對話框
LPITEMIDLIST lpIDList = SHBrowseForFolder (&bi);
if (lpIDList) { //取得資料夾路徑至Buffer裡
SHGetPathFromIDList(lpIDList, szPathBuf);
if(memcmp(szPathBuf, "", sizeof(szPathBuf)) != 0) {
m_edPath.SetWindowText((LPCTSTR)szPathBuf);
m_csPath = szPathBuf;
}
}
LPMALLOC lpMalloc;
if(FAILED(SHGetMalloc(&lpMalloc))) return; //釋放內存
lpMalloc->Free(lpIDList);
lpMalloc->Release();
}
/*
如果想要在瀏覽資料夾的對話框開啟時,展開樹狀目錄在特定的資料夾上時,可做下列修改:
LPCTSTR lpszInitialPath = m_csPath;
bi.lpfn = BrowseCallBackProc;
bi.lParam = (LPARAM)lpszInitialPath; //預設的資料夾
然後再上面的OnBTGetPath()之前加上:
int CALLBACK BrowseCallBackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData){
if (uMsg == BFFM_INITIALIZED && lpData != NULL) {
::SendMessage(hwnd, BFFM_SETSELECTION, true, lpData);
}
return 0;
}
*/
沒有留言:
張貼留言