Click to See Complete Forum and Search --> : Browse Dialog Box


June 1st, 1999, 09:00 AM
I am looking to create a Directory selection dialog box.
to see what im trying to do go to options/directories in VC++ 6 & browse for a directory.

so far I am using "SHBrowseForFolder", which is allowing me to browse the directories.

I have included the code i have so far, where to next?
also not sure if i have handled BFFM_VALIDATEFAILED well enough.

thanks
A
int CALLBACK BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lParam,LPARAM lpData)
{
TCHAR szDir[MAX_PATH];

switch(uMsg)
{
case BFFM_INITIALIZED:
{
// WParam is TRUE since you are passing a path.
// It would be FALSE if you were passing a pidl.
if(GetCurrentDirectory(sizeof(szDir)/sizeof(TCHAR),szDir))
SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)szDir);

break;
}
case BFFM_SELCHANGED:
{
// Set the status window to the currently selected path.
if (SHGetPathFromIDList((LPITEMIDLIST) lParam ,szDir))
SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)szDir);

break;
}
case BFFM_VALIDATEFAILED:
{
AfxMessageBox("?");
return 1;
}
default:
break;
}
return 0;
}

void CTestdirDlg::OnButton1()
{
BROWSEINFO bi;
LPVOID pvReserved=NULL;
//HWND hWnd;//init
LPARAM mylParam=NULL;
UINT uMsg=0;
LPARAM lpData=NULL;
int nImage=0;

TCHAR szDir[MAX_PATH];
LPITEMIDLIST pidl;


CoInitialize(pvReserved);

bi.hwndOwner=NULL; //handle to owner window
bi.pidlRoot=0;
bi.pszDisplayName=0; //Address of a buffer to receive the display name of the selected folder.
//bi.lpszTitle=pszTitleText;
bi.ulFlags=BIF_EDITBOX |BIF_RETURNFSANCESTORS |BIF_RETURNONLYFSDIRS |BIF_STATUSTEXT |BIF_VALIDATE; //|BIF_USENEWUI;
bi.lpfn=BrowseCallbackProc;
bi.lParam=mylParam;
bi.iImage=nImage;

pidl = SHBrowseForFolder(&bi);
if (pidl)
{
if (SHGetPathFromIDList(pidl,szDir))
{

}
}
}