...get the startmenu's directory ?

Author: Rainer K├╝mmerle
Homepage: http://www.thinklazy.de

Category: System

uses
  
ShlObj, ActiveX;

procedure FreePidl(pidl: PItemIDList);
var
  
allocator: IMalloc;
begin
  if 
Succeeded(SHGetMalloc(allocator)) then
  begin
    
allocator.Free(pidl);
    {$IFDEF VER100}
    
allocator.Release;
    {$ENDIF}
  
end;
end;

function GetStartMenu: string;
var
  
pidl: PItemIDList;
  buf: array[0..MAX_PATH] of Char;
begin
  if 
Succeeded(SHGetSpecialFolderLocation(Form1.Handle, CSIDL_STARTMENU, pidl)) then
  
SHGetPathFromIDList(pidl, buf);
  Result := StrPas(buf);
  // The calling application is responsible for freeing the PItemIDList-pointer
  // with the Shell's IMalloc interface
  
FreePIDL(pidl);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  
label1.Caption := GetStartMenu;
end;

 

printed from
www.swissdelphicenter.ch
developers knowledge base