SHGetSpecialFolderLocationとSHGetPathFromIDListのコンビネーションです。
実際のフォルダの作成には、CreateDirectoryを使っています。
uses shlobj; function CreateFolder(Foldername: String; aLocation: integer): boolean; var pIdl: PItemIDList; hPath: PChar; begin Result := False; if SUCCEEDED(SHGetSpecialFolderLocation(0, aLocation, pidl)) then begin hPath := StrAlloc(max_path); SHGetPathFromIDList(pIdl, hPath); SetLastError(0); CreateDirectory(PChar(hPath + '\\' + Foldername), nil); if (GetLastError()=0) or (GetLastError() = ERROR_ALREADY_EXISTS) then begin Result := true; end; StrDispose(hPath); end; end; procedure TForm1.Button1Click(Sender: TObject); begin // constants like 'CSIDL_PROGRAMS' are defined in ShlObj CreateFolder('MyProgramgroup',CSIDL_PROGRAMS); end;
コメント (0件)