uses ShellAPI, ShlObj;
function SHBrowseForFolder (var BrowseInfo: TBrowseInfo): PItemIDList; stdcall;
function BrowseDialog (const Title: string; const Flag: integer): string;
var
lpItemID : PItemIDList;
BrowseInfo : TBrowseInfo;
DisplayName : array[0..MAX_PATH] of char;
TempPath : array[0..MAX_PATH] of char;
begin
Result:='';
FillChar(BrowseInfo, sizeof(TBrowseInfo), #0);
with BrowseInfo do begin
hwndOwner := Application.Handle;
pszDisplayName := @DisplayName;
lpszTitle := PChar(Title);
ulFlags := Flag;
end;
lpItemID := SHBrowseForFolder(BrowseInfo);
if lpItemId <> nil then begin
SHGetPathFromIDList(lpItemID, TempPath);
Result := TempPath;
GlobalFreePtr(lpItemID);
end;end;
procedure TfrMain.btnBrowseClick(Sender: TObject);
var sTitle, sFolder: string;
iFlag : integer;
begin
sTitle:='Choose a ' + rgBrowseFor.Items[rgBrowseFor.ItemIndex];
case rgBrowseFor.ItemIndex of
0: iFlag := BIF_RETURNONLYFSDIRS;
1: iFlag := BIF_BROWSEINCLUDEFILES;
2: iFlag := BIF_BROWSEFORCOMPUTER;
3: iFlag := BIF_BROWSEFORPRINTER;
end;
sFolder := BrowseDialog(sTitle, iFlag);
if sFolder <> '' then
edSelected.text := sFolder
else
edSelected.text := 'Nothing selected';
end;
Resim1.jpg
***YADA***
uses ShellAPI, ShlObj;
procedure TForm1.Button1Click(Sender: TObject);
var
TitleName : string;
lpItemID : PItemIDList;
BrowseInfo : TBrowseInfo;
DisplayName : array[0..MAX_PATH] of char;
TempPath : array[0..MAX_PATH] of char;
begin
FillChar(BrowseInfo, sizeof(TBrowseInfo), #0);
BrowseInfo.hwndOwner := Form1.Handle;
BrowseInfo.pszDisplayName := @DisplayName;
TitleName := 'Please specify a directory';
BrowseInfo.lpszTitle := PChar(TitleName);
BrowseInfo.ulFlags := BIF_RETURNONLYFSDIRS;
lpItemID := SHBrowseForFolder(BrowseInfo);
if lpItemId <> nil then begin
SHGetPathFromIDList(lpItemID, TempPath);
ShowMessage(TempPath);
GlobalFreePtr(lpItemID);
end; end;
Hiç yorum yok:
Yorum Gönder