views:

238

answers:

1

I am using visual studio 2008...I am tryin to get the folder path for my output file in my design ...I know there is a class called CFolderDialog ..but its not working in my pgm..should I include any header file inorder to get that..if YES,can anybody tell me how to include in visual studio 2008..plz help me

A: 

Forget about the CFolderdialog..instead of that..iam using another to get the folder path...check my code below....am getting a run time error when i try toprint the folder path name in a edit box..

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) { // If the BFFM_INITIALIZED message is received // set the path to the start path. switch (uMsg) { case BFFM_INITIALIZED: { if (NULL != lpData) { SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData); } } }

return 0; // The function should always return 0.

}

kiddo