Thema: Delphi Programm Ordner finden

Einzelnen Beitrag anzeigen

hathor
(Gast)

n/a Beiträge
 
#4

Re: Programm Ordner finden

  Alt 6. Apr 2008, 13:28
Das Thema wurde hier schon x-mal behandelt, aber da muss man natürlich den Suchbegriff GETSPECIALFOLDER kennen.

Delphi-Quellcode:
uses
  { ... },
  ActiveX, // IMalloc
  ShellAPI, // SHGetSpecialFolderLocation() und SHGetPathFromIDList()
  ShlObj; // CSIDL_-Konstanten

.
.
.

function GetSpecialFolder(hWindow: HWND; Folder: Integer): String;
var
pMalloc: IMalloc;
pidl: PItemIDList;
Path: PChar;
begin
// get IMalloc interface pointer
if (SHGetMalloc(pMalloc) <> S_OK) then
begin
MessageBox(hWindow, 'Couldn''t get pointer to IMalloc interface.','SHGetMalloc(pMalloc)', 16);
Exit;
end;
// retrieve path
SHGetSpecialFolderLocation(hWindow, Folder, pidl);
GetMem(Path, MAX_PATH);
SHGetPathFromIDList(pidl, Path);
Result := Path;
FreeMem(Path);

// free memory allocated by SHGetSpecialFolderLocation
pMalloc.Free(pidl);
end;

//Mit folgendem Aufruf werden alle Specialfolder angezeigt, die auf DIESEM PC zur Verfügung stehen:
for i := 0 to 64 do Memo1.Lines.add(IntToStr(i)+' : '+ GetSpecialFolder(Form1.Handle,i));
  Mit Zitat antworten Zitat