記事カテゴリ

ユーザー機能


 2024年4月29日(月) 07:45 JST

[Delphi] スタートメニューにプログラムグループを作る

  • 投稿者:
  • 表示回数
    3,496

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;

トラックバック

このエントリのトラックバックURL:
https://www.blackcat.xyz/trackback.php/ProgramingFAQ_del0011

以下のコメントは、その投稿者が所有するものでサイト管理者はコメントに関する責任を負いません。