我正在使用以下函数..而不是CFolderDialog ..来获取文件夹路径...检查下面的代码....当我尝试在编辑框中打印文件夹路径名时出现运行时错误..
空隙 CSelfExtractorUIDlg :: OnBnClickedButton1() {
CDialog dlg;
HWND hwnd = NULL; LPCTSTR szCurrent = (LPCTSTR)的malloc(25 *的sizeof(TCHAR)); szCurrent = NULL; LPTSTR szPath = (LPTSTR)malloc的(25 *的sizeof(TCHAR)); BOOL 检查= BrowseForFolder(HWND,szCurrent,szPath); if(check == TRUE){ dlg.SetDlgItemTextW(IDC_EDIT1,szPath); }
}
BOOL BrowseForFolder(HWND hwnd, LPCTSTR szCurrent,LPTSTR szPath){ BROWSEINFO bi = {0}; LPITEMIDLIST PIDL; TCHAR szDisplay [256]; BOOL RETVAL;
// CoInitialize的();
bi.hwndOwner = hwnd; bi.pszDisplayName = szDisplay; bi.lpszTitle = TEXT(“请 选择一个文件夹。“); bi.ulFlags
= BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; bi.lpfn
= BrowseCallbackProc; bi.lParam =(LPARAM)szCurrent;pidl = SHBrowseForFolder(& bi);
if(NULL!= pidl){ retval = SHGetPathFromIDList(pidl,szPath); CoTaskMemFree(PIDL); } else { retval = FALSE; }
if(!retval){ szPath [0] = TEXT('\ 0'); }
CoUninitialize();返回retval;
} static int CALLBACK BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lParam,LPARAM lpData) { //如果BFFM_INITIALIZED消息是 收到//设置开始的路径 路径。
开关(uMsg){案例 BFFM_INITIALIZED:{if(NULL!= lpData){SendMessage(hwnd, BFFM_SETSELECTION,TRUE,lpData); } }}返回0; //功能
答案 0 :(得分:0)
对于完整路径长度,25个字符似乎有点短,我使用MAX_PATH。