Newsgroup: it.comp.lang.delphi
Titolo: Ricavare la Path del cestino

 Come posso fare a ricavare la path del cestino?
Indipendentemete dal SO [varie versioni di win] che è installato?
--- posted by geoForum on 
http://www.delphiedintorni.it

function SHGetSpecialFolderLocation(    hwndOwner : HWND;  nFolder   : integer;  var ppidl     : PItemIDList) : HResult;
Stdcall;             external 'Shell32.dll'  name     'SHGetSpecialFolderLocation';
Function SelezionaCartellaParticolare(Handle   : HWND;  Cartella : Integer) : String;
var
  pidlBrowse     : PItemIDList;
  pszPath        : array[0..MAX_PATH] of char;
  ppMalloc       : IMalloc;
  S              : String;
begin
  CoInitialize(Nil);
  CoGetMalloc(1, ppMalloc);
  S  := '';
  If SHGetSpecialFolderLocation(Handle, Cartella, pidlBrowse) = NOERROR Then
     try
      if (pidlBrowse <> nil) then
         begin
           SHGetPathFromIDList(pidlBrowse, @pszPath);
           S := StrPas(pszPath);
         end;
      finally
      end;
  ppMalloc.Free(pidlBrowse);
  CoUninitialize;
  Result := S;
end;
Come CARTELLA passa una di queste (quella che interessa a te č CSIDL_BITBUCKET)
Const
  CSIDL_DESKTOP            = $0000;         // Desktop
  CSIDL_PROGRAMS           = $0002;         // Programmi
  CSIDL_CONTROLS           = $0003;         // Controlli
  CSIDL_PRINTERS           = $0004;         // Stampanti
  CSIDL_PERSONAL           = $0005;         // Personali
  CSIDL_FAVORITES          = $0006;         // Preferiti
  CSIDL_STARTUP            = $0007;         // Iniziale
  CSIDL_RECENT             = $0008;         // Recenti
  CSIDL_SENDTO             = $0009;         // Invia a...
  CSIDL_BITBUCKET          = $000A;         // Cestino
  CSIDL_STARTMENU          = $000B;         // Start menu
  CSIDL_DESKTOPDIRECTORY   = $0010;         // Desktop Directory
  CSIDL_DRIVES             = $0011;         // Driver
  CSIDL_NETWORK            = $0012;         // Rete
  CSIDL_NETHOOD            = $0013;         // Risorse di rete
  CSIDL_FONTS              = $0014;         // Font
  CSIDL_TEMPLATES          = $0015;         // Nuovo...
  CSIDL_AvvioAll           = $0016;         // Menů avvio                (All user)
  CSIDL_ProgrammiAll       = $0017;         // Programmi                 (All user)
  CSIDL_StartupAll         = $0018;         // Esecuzione automatica     (All user)
  CSIDL_DesktopAll         = $0019;         // Desktop                   (All user)
  CSIDL_PreferitiAll       = $001F;         // Preferiti                 (All user)
  CSIDL_INTERNETTemp       = $0020;         // Temporanei Internet
  CSIDL_Cookies            = $0021;         // Cookies
  CSIDL_Cronologia         = $0022;         // Cronologia
  CSIDL_AppDataAll         = $0023;         // Dati applicazioni         (All user)
  CSIDL_WinDir             = $0024;         // WinDir
  CSIDL_SysDir             = $0025;         // SysDir
  CSIDL_IstPrograms        = $0026;         // Istallazione Programmi
  CSIDL_Documenti          = $0027;         // Documenti
  CSIDL_Administrator      = $0028;         // Administrator
  CSIDL_Sys32Dir           = $0029;         // Sys32Dir
  CSIDL_FileComuni         = $002B;         // File Comuni
  CSIDL_ModelliAll         = $002D;         // Modelli                   (All user)
  CSIDL_DocumentiAll       = $002E;         // Documenti                 (All user)
  CSIDL_AmministrazioneAll = $002F;         // Strumenti amministrazione (All user)
  CSIDL_Accessori          = $0030;         // Accessori
--
Ciao,
David

 Stdcall;             external 'Shell32.dll'  name     'SHGetSpecialFolderLocation';
Scusate se mi intrometto ma dove è definito PItemIDList?
Se copio il codice che hai postato in una nuova applicazione mi becco un
bel "Undeclared identifier"...
Saluti
	Marco Bortolani
	info @ 
marcobortolani.it

Ops non ho copiato il codice (tradotto letteralmente dal SDK si puo' modificare ovviamente)
Type
  PSHItemID = ^TSHItemID;
  TSHItemID = record
                 cb   : word;
                 abID : array[0..0] of BYTE;
              end;
  PItemIDList = ^TItemIDList;
  TItemIDList = record
                   mkid: TSHITEMID;
                end;
--
Ciao,
David

Mah io io... a me non funziona!


Uhm... adesso brontola per IMalloc...
Suvvia, David, non ci abbandonare!
Saluti
	Marco


Piu' semplicemente:
uses shlObj, ActiveX;
procedure TForm1.Button1Click(Sender: TObject);
var  pIIdL     : pItemIdList;
     pMAlloc   : iMalloc;
     path      : array [0 .. Max_Path] of char;
begin
if shGetSpecialFolderLocation (Handle, CSIDL_STARTUP, pIIdL) = NoError
then begin
     if shGetPathFromIdList (pIIdl, @path [0])
     then Edit1.Text := StrPas (@path [0]);
     if shGetMalloc (pMalloc) = NoError
     then pMalloc.Free (pIIdl);
     end;
end;
Ciao.
--
ACSH
[D4]
---------------------------
Chi fa da se'
fatica il doppio

      end;
Ho provato a farla girare con tutti gli special folder definiti in ShlObj
ma per alcuni la shGetPathFromIdList non ritorna True.. in particolare,
neanche per CSIDL_BITBUCKET :-((
Altre idee?
	Marco
P.S.
Posto il codice di visualizzazione: sul form ho messo un bottone e una
StringGrid con due righe e due colonne:
procedure TForm1.Button1Click(Sender: TObject);
const CSIDL_BITBUCKET = $000A;
var  pIIdL     : pItemIdList;
     pMAlloc   : iMalloc;
     path      : array [0 .. Max_Path] of char;
     i         : Integer;
begin
    StringGrid1.RowCount := 2;
    StringGrid1.Cells[1, 1] := '';
    StringGrid1.Cells[2, 1] := '';
    i := 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_STARTUP, pIIdL) = NoError
then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_STARTUP';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, i] := StrPas(@path [0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_DESKTOP, pIIdL) = NoError
then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_DESKTOP';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_INTERNET, pIIdL) = NoError
then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_INTERNET';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_PROGRAMS, pIIdL) = NoError
then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_PROGRAMS';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_CONTROLS, pIIdL) = NoError
then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_CONTROLS';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_PRINTERS, pIIdL) = NoError
then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_PRINTERS';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_PERSONAL, pIIdL) = NoError
then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_PERSONAL';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_FAVORITES, pIIdL) =
NoError then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] :=
'CSIDL_FAVORITES';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_STARTUP, pIIdL) = NoError
then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_STARTUP';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_RECENT, pIIdL) = NoError
then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_RECENT';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_SENDTO, pIIdL) = NoError
then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_SENDTO';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_BITBUCKET, pIIdL) =
NoError then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] :=
'CSIDL_BITBUCKET';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_STARTMENU, pIIdL) =
NoError then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] :=
'CSIDL_STARTMENU';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_DESKTOPDIRECTORY, pIIdL) =
NoError then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_STARTUP';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_DRIVES, pIIdL) = NoError
then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_STARTUP';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_NETWORK, pIIdL) = NoError
then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_STARTUP';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_NETHOOD, pIIdL) = NoError
then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_NETHOOD';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_FONTS, pIIdL) = NoError
then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_FONTS';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_TEMPLATES, pIIdL) =
NoError then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] :=
'CSIDL_TEMPLATES';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_COMMON_STARTMENU, pIIdL) =
NoError then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_STARTUP';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_COMMON_PROGRAMS, pIIdL) =
NoError then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_STARTUP';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_COMMON_STARTUP, pIIdL) =
NoError then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_STARTUP';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_COMMON_DESKTOPDIRECTORY,
pIIdL) = NoError then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] :=
'CSIDL_COMMON_DESKTOPDIRECTORY';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_APPDATA, pIIdL) = NoError
then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_APPDATA';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_PRINTHOOD, pIIdL) =
NoError then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] :=
'CSIDL_PRINTHOOD';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_ALTSTARTUP, pIIdL) =
NoError then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] :=
'CSIDL_ALTSTARTUP';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_COMMON_ALTSTARTUP, pIIdL)
= NoError then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] :=
'CSIDL_COMMON_ALTSTARTUP';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_COMMON_FAVORITES, pIIdL) =
NoError then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] :=
'CSIDL_COMMON_FAVORITES';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_INTERNET_CACHE, pIIdL) =
NoError then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] :=
'CSIDL_INTERNET_CACHE';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_COOKIES, pIIdL) = NoError
then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_COOKIES';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path
[0]);
        if shGetMalloc (pMalloc) = NoError then
            pMalloc.Free (pIIdl);
    end;
    StringGrid1.RowCount := StringGrid1.RowCount + 1;
    if shGetSpecialFolderLocation (Handle, CSIDL_HISTORY, pIIdL) = NoError
then
    begin
        StringGrid1.Cells[1, StringGrid1.RowCount - 1] := 'CSIDL_HISTORY';
        if shGetPathFromIdList (pIIdl, @path [0]) then
            StringGrid1.Cells[2, StringGrid1.RowCount - 1] := StrPas(@path


 Altre idee?
Beh, si': il mare, le onde, una spiaggia, un ombrellone, un drink, una
bionda o
una mora al fianco (o meglio: una bionda E una mora al fianco) ...


 una mora al fianco (o meglio: una bionda E una mora al fianco) ...
LOLL! Concordo e sottoscrivo!
	Marco