////////////////////////////////////////////////////////////////////////////////
// Tip 6 - display a nice directory selection dialog
// using the Explore FolderBrowser
//
// (Sample routine)
////////////////////////////////////////////////////////////////////////////////
procedure TMain.ShowExplorerDirBtnClick(Sender: TObject);
var
sDir : string ;
begin
sDir := ShellShowDirs (self.Handle);
if ( length(sDir) > 0 ) then
ShowMessage ('Directory is:' + sDir )
else
ShowMessage ('No Directory Selected.') ;
end ;
///////////////////////////////////////////////////////////////////////////////
// Name: ShellShowDirs
// Actual Work code which displays Explore Dir Browser
//
//
//////////////////////////////////////////////////////////////////////////////
function ShellShowDirs ( AHandle : HWND ): string ;
var
BrowsingInfo : TBrowseInfo ;
// BrowsingInfo;
DirPath : String ;
// char DirPath[MAX_PATH];
FolderName : string ;
// char FolderName[MAX_PATH];
pItemId : PItemIDList;
// LPITEMIDLIST ;
// ItemID;
begin
DirPath := '' ;
FolderName := '' ;
// pad the strings with blanks, they have to bedo
ne this way or
// SHBrowseForFolderA and/or SHGetPathFromIDList gpf.
DirPath := StringOfChar(' ', MAX_PATH);
FolderName := StringOfChar (' ' , MAX_PATH) ;
// handle dictates who owns the dialog which pops up.
BrowsingInfo.hwndOwner := AHandle ;
// self.Handle ;
BrowsingInfo.pszDisplayName := PChar(FolderName) ;
BrowsingInfo.lpszTitle := PAnsiChar('Johns Dir Demo') ;
BrowsingInfo.ulFlags := BIF_RETURNONLYFSDIRS
and BIF_DONTGOBELOWDOMAIN ;
BrowsingInfo.pidlRoot := nil ;
BrowsingInfo.lpfn := nil ;
// display the dialog
pItemID := SHBrowseForFolderA( BrowsingInfo );
// determine what the selection was
SHGetPathFromIDList(pItemID, PChar(DirPath));
// back to caller
result := PChar(DirPath) ;
// pItemId actually points to some memory, so free it
GlobalFreePtr(pItemID);
end;