QC20N
asked on
Opendialog only for Folder
Hi, I'm looking for a OpenDialog but only for folders.
I need to have the user of my application to open all files from a folder with a specific extension.
How do I do that? I know the OpenDialog. But that is only for files.
I need to have the user of my application to open all files from a folder with a specific extension.
How do I do that? I know the OpenDialog. But that is only for files.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use this function
Call it this way
var
Folder: string;
begin
Folder := 'c:\'; //initial folder
if BrowseDirectoryDialog('Sel ect Folder', BIF_RETURNONLYFSDIRS, Folder) then
begin
//your code
end;
end;
uses
ShlObj;
function BrowseDialogCallBack(Wnd: HWnd; uMsg: UINT; lParam, lpData: LParam): Integer stdcall;
var
WA, R: TRect;
PT: TPoint;
begin
if uMsg = BFFM_INITIALIZED then
begin
WA := Screen.WorkAreaRect;
GetWindowRect(Wnd, R);
PT.X := ((WA.Right - WA.Left) div 2) - ((R.Right - R.Left) div 2);
PT.Y := ((WA.Bottom - WA.Top) div 2) - ((R.Bottom - R.Top) div 2);
MoveWindow(Wnd, PT.X, PT.Y, R.Right - R.Left, R.Bottom - R.Top, True);
SendMessage(Wnd, BFFM_SETSELECTION, Ord(True), Integer(lpData));
end;
Result := 0;
end;
function BrowseDirectoryDialog(const ATitle: string; const AFlag: Integer;
var Dir: string): Boolean;
var
lpItemID: PItemIDList;
BrowseInfo: TBrowseInfo;
DisplayName, TempPath: array[0..MAX_PATH] of Char;
begin
FillChar(BrowseInfo, SizeOf(TBrowseInfo), #0);
with BrowseInfo do
begin
hwndOwner := Application.Handle;
pszDisplayName := @DisplayName;
lpszTitle := PChar(ATitle);
ulFlags := AFlag;
lpfn := BrowseDialogCallBack;
lParam := Integer(PChar(Dir));
end;
lpItemID := ShlObj.SHBrowseForFolder(BrowseInfo);
Result := lpItemId <> nil;
if Result then
begin
ShlObj.SHGetPathFromIDList(lpItemID, TempPath);
Dir := TempPath;
GlobalFreePtr(lpItemID);
end;
end;
Call it this way
var
Folder: string;
begin
Folder := 'c:\'; //initial folder
if BrowseDirectoryDialog('Sel
begin
//your code
end;
end;
Excuse me, ewangoya, but why you suggest to use something else than the built in function? I ask this because I really don't uderstand where is the advantage using such a function as that you have suggested...
Cheers