1. uses ShlObj, ShellApi, KnownFolders;
  2. {$R *.dfm}
  3. procedure TForm5.FormCreate(Sender: TObject);
  4. const iconSize : TSize = (cx : 16; cy:16);
  5. var cpItem, cpEntry : IShellItem;
  6. CPFolder : IShellFolder;
  7. DesktopFolder : IShellFolder;
  8. cpIDList, cpEntryID : PItemIDList;
  9. eidList : IEnumIDList;
  10. fetched : cardinal;
  11. cpDisplay : TStrRet;
  12. sif : IShellItemImageFactory;
  13. mi : TMenuItem;
  14. bmp : TBitmap;
  15. hbmp : HBITMAP;
  16. begin
  17. SHGetKnownFolderIDList(FOLDERID_ControlPanelFolder, 0, 0, cpIDList);
  18. SHGetDesktopFolder(DesktopFolder);
  19. DesktopFolder.BindToObject(cpIDList, nil, IID_IShellFolder, CPFolder);
  20. CPFolder.EnumObjects(handle, SHCONTF_FOLDERS + SHCONTF_NONFOLDERS, eIdList );
  21. while S_OK = eIdList.Next(1, cpEntryID, fetched) do begin
  22. CPFolder.GetDisplayNameOf(cpEntryID, SIGDN_NORMALDISPLAY, cpDisplay);
  23. SHCreateItemFromIDList(cpEntryId, IID_IShellItemImageFactory, sif);
  24. bmp := TBitmap.Create();
  25. bmp.SetSize(16,16);
  26. bmp.PixelFormat := pf32bit;
  27. bmp.AlphaFormat := afPremultiplied;
  28. sif.GetImage(iconSize, SIIGBF_RESIZETOFIT, hbmp);
  29. bmp.Handle := hbmp;
  30. mi := TMenuItem.Create(cpMenu);
  31. mi.Bitmap := bmp;
  32. mi.Caption := cpDisplay.pOleStr;
  33. //add item to cpMenu : TPopupMenu
  34. cpMenu.Items.Add(mi);
  35. end;
  36. end;

Enumerating Control panel items using Shell API

Comments powered by Disqus