Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
|
Browsing through Windows folders
This article has not been rated yet. After reading, feel free to leave comments and rate it.
The two key functions to browse through those virtual Windows folders are
SHGetSpecialFolderLocation();
and
SHGetPathFromIDList()
They can be used as shown in the sample code. You may replace the CSIDL_PROGRAMS constant with another one from the list in the comment below.  | |  | | uses ShlObj,ActiveX;
procedure TForm1.Button1Click(Sender: TObject);
var
BI: TBrowseInfo;
Buf: PChar;
Dir,
Root: PItemIDList;
Alloc: IMalloc;
begin
SHGetMalloc(Alloc);
Buf := Alloc.Alloc(Max_Path);
SHGetSpecialFolderLocation(Handle, CSIDL_PROGRAMS, Root);
with BI do
begin
hwndOwner := Form1.Handle;
pidlRoot := Root;
pszDisplayName := Buf;
lpszTitle := 'Choose Folder';
ulFlags := 0;
lpfn := nil;
end;
try
Dir := SHBrowseForFolder(BI);
if Dir<>nil then
begin
SHGetPathFromIDList(Dir, Buf);
ShowMessage(Buf);
Alloc.Free(Dir);
end;
finally
Alloc.Free(Root);
Alloc.Free(Buf);
end;
end; | |  | |  | You don't like the formatting? Check out SourceCoder then!
Comments:
|