Sorting shell items like windows explorer

Posted by Roy M Klever on Stack Overflow See other posts from Stack Overflow or by Roy M Klever
Published on 2010-05-30T12:38:51Z Indexed on 2010/05/30 12:42 UTC
Read the original article Hit count: 408

Filed under:
|
|
|
|

Hi,

I am making a bread crumb bar in Delphi and having some problems regarding sorting the dropdown of the bread crumbs.

Strangely enough, even Vista is not consequent when showing these items.

I have tried many ways to figure out what is system folders, what is zip files and what is normal folders. It seems like an easy task but so far I have not found any good way of doing it.

One way is to use TypeDisplayName from TSHFileinfo but these are localized names so I can not be sure they will be in correct order in every language.

Here is the code I use to fill the menu:

  bool:= IsDesktop(SelectedPIDL);
  if bool then
    OleCheck(SHGetDesktopFolder(CurFolder))
  else
    OleCheck(DesktopShellFolder.BindToObject(SelectedPIDL, nil, IID_IShellFolder, Pointer(CurFolder)));
  if CurFolder.EnumObjects(0, SHCONTF_FOLDERS, EnumIDList) = NOERROR then
  begin
    while EnumIDList.Next(1, CurPidl, Fetched) = S_OK do
    begin
      FName:= GetDisplayName(CurFolder, CurPidl, SHGDN_NORMAL);
      Text:= GetPIDLNameForAddressBar(CurFolder, CurPidl);
      if bool then
        Text:= PSpecialFolderItem(SpecialFolders[0]).Name + '\' + Text;
      if Text[Length(Text)] <> '\' then
        Text:= Text + '\';
      NewPidl:= ConcatPIDLs(SelectedPIDL, CurPidl);
      SHGetFileInfo(PChar(NewPidl), 0, SFI, SizeOf(SFI), SHGFI_ATTRIBUTES or SHGFI_PIDL or
        SHGFI_SYSICONINDEX or SHGFI_TYPENAME);

      n:= SFI.dwAttributes;
      MenuList.Add(GetAttr(n) + FName);

      AddMenuItem(Text, FName, SFI.iIcon);
      CoTaskMemFree(CurPidl);
      CoTaskMemFree(NewPidl);
    end;
  end;
  CoTaskMemFree(SelectedPIDL);

Any solution for how to get the correct sorting order? It is strange there is no way in dwAttributes of TSHFileInfo to tell if a folder is a system folder.

Roy M Klever

© Stack Overflow or respective owner

Related posts about delphi

Related posts about shell