我正在使用visual studio 2008 ...我正在尝试在我的设计中获取输出文件的文件夹路径...我知道有一个名为CFolderDialog的类..但它不能在我的pgm ...中工作我包含任何头文件以便获得..如果是,有人可以告诉我如何在visual studio 2008中包含..plz帮助我
答案 0 :(得分:0)
忘掉CFolderdialog ..而不是那个......用另一个来获取文件夹路径...检查下面的代码....当我尝试在编辑中打印文件夹路径名时出现运行时错误箱..
void CSelfExtractorUIDlg :: OnBnClickedButton1() {
CDialog dlg;
HWND hwnd = NULL;
LPCTSTR szCurrent = (LPCTSTR)malloc(25*sizeof(TCHAR));
szCurrent = NULL;
LPTSTR szPath = (LPTSTR)malloc(25*sizeof(TCHAR));
BOOL check = 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("Please choose a folder.");
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();
return 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); } } }
return 0; // The function should always return 0.
}