All pastes #12605 Raw Edit

Miscellany

public text v1 · immutable
#12605 ·published 2005-05-25 16:26 UTC
rendered paste body
function SpecialFolderPath(H: hWnd; W: Integer): String;
var
 T: PItemIDList;
 C: PChar;
begin
 Result := '';
 New(C);
 // A nice API to get a list of all special locations into a PItemIDList
 SHGetSpecialFolderLocation(H, W, T);
 // Some memory for our pchar
 GetMem(C, 512);
 // Get the wanted path
 SHGetPathFromIDList(T, C);
 Result := C;
 // We don't want to waste resources
 FreeMem(C);
end;


This requires a fancy unit named ShlObj.pas, found in Delphi's Source\Rtl\Win\ folder.
The list of possible second parameters for this are:

CODECSIDL_BITBUCKET - Recycle bin (can only be found with the above API)
CSIDL_CONTROLS - Control panel (Virtual folder)
CSIDL_DESKTOP - Windows desktop (Virtual folder)
CSIDL_DESKTOPDIRECTORY - Physical object storage of current desktop
CSIDL_DRIVES - My Computer (Virtual folder)
CSIDL_FONTS - Fonts folder
CSIDL_NETWORK - Network Neighborhood (Virtual folder)
CSIDL_PERSONAL - Personal documents folder
CSIDL_PRINTERS - Installed printers (Virtual folder)
CSIDL_PROGRAMS - Program groups
CSIDL_RECENT - Recent documents link folder
CSIDL_SENDTO - "Send To:"-menu item folder
CSIDL_STARTMENU - Start menu items group folder
CSIDL_STARTUP - "Startup" program group folder
CSIDL_TEMPLATES - Document template dir


There's also one named CSIDL_NETHOOD, I'm not sure what it is.

Example call of the above function:
CODEprocedure TForm1.Button1Click(Sender: TObject);
begin
 Edit1.Text := SpecialFolderPath(Form1.Handle, CSIDL_FONTS);
end;


Note that some of the directories may not exist in all Windows® versions.
Have fun.

This post has been edited by prevex: Apr 25 2005, 07:01 PM