Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Quick One! Windows XP Directory Structure

Posted on 2003-03-19
4
Medium Priority
?
153 Views
Last Modified: 2010-04-03
How can I use a list box to show the WindowsXP Directory Hierarchy?? IE:

Desktop
  |-My Documents
  |-My Computer

etc...

I dont want a tree I just want to know what API I would use to use this structure instead of the typical C:\blah. Where Desktop is the root directory instead of C:\ - get it?

Here's 500 points for a quick answer!

0
Comment
Question by:mdlittle
  • 2
4 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8172144
the start would be

SHGetDesktopFolder()

from help-file

Retrieves the IShellFolder interface for the desktop folder, which is the root of the shell's name space.

WINSHELLAPI HRESULT WINAPI SHGetDesktopFolder(

    LPSHELLFOLDER *ppshf    
   );    
 

Parameters

ppshf

Address that receives an IShellFolder interface pointer for the desktop folder. The calling application is responsible for eventually freeing the interface by calling its Release method.

 

Return Values

Returns NOERROR if successful or an OLE-defined error result otherwise.

See Also

IShellFolder

about IShellFolder

he IShellFolder interface is used to manage folders.

When to Implement

Implement IShellFolder for objects that extend the shell's namespace. For example, if you create a separate name space that requires a rooted Explorer; or if you install a new name space directly within the hierarchy of the system name space.Only you know anything about the contents of your name space so you are responsible for implementing everything needed to access your data.

When to Use

Use IShellFolder when you need to display or operate on the contents of the shell's namespace. Objects that support IShellFolder are usually created by other shell folder objects, with the root object (the Desktop shell folder) being returned from the SHGetDesktopFolder function.

Methods in Vtable Order

IUnknown Methods     Description
QueryInterface     Returns pointers to supported interfaces.
AddRef     Increments reference count.
Release     Decrements reference count.
 

IShellFolder Methods     Description
ParseDisplayName     Translates a display name into an item identifier list.
EnumObjects     Enumerates the objects in a folder.
BindToObject     Retrieves the IShellFolder interface for the specified subfolder.
BindToStorage     Returns the storage instance of a subfolder.
CompareIDs     Compares two item identifier lists and returns the result.
CreateViewObject     Creates a view object of the folder itself.
GetAttributesOf     Retrieves the attributes of the specified file object or subfolder.
GetUIObjectOf     Creates an OLE interface that can be used to carry out operations on a file object or subfolder.
GetDisplayNameOf     Retreives the display name of a file object or subfolder.
SetNameOf     Sets the display name of the specified file object or subfolder and changes its identifier accordingly.
 

meikl ;-)
0
 

Author Comment

by:mdlittle
ID: 8176039
I don't suppose you have some sample code I could look at? I want to create a list box that follows the Windows 2000 / XP directory hierarchy. Thanks for the help
0
 
LVL 35

Accepted Solution

by:
Slick812 earned 2000 total points
ID: 8177972
hello mdlittle, What you ask for requires that you get the Shell Folder structure, instead of the Disk Operating System (FAT Table) structure, the IShellFolder can be very usefull, but it takes some adjustment to deal with the IShellFolder Interface, which uses Item Lists (ItemIDList) instead of Path strings. Here is some code that might help you to get started with the "Desktop" folder structure.. . It uses a List box, like you said. . . It uses One Button and One TListBox -



function Form1.GetPItemName(IShellF: IShellFolder; PItemID: PItemIDList): String;
var
StrRet: TStrRet;
Pstr: PChar;
begin
OleCheck(IShellF.GetDisplayNameOf(PItemID, SHGDN_NORMAL, StrRet));
case StrRet.uType of
  STRRET_CSTR: SetString(Result, StrRet.cStr, StrLen(StrRet.cStr));
  STRRET_OFFSET:
    begin
    Pstr := @PItemID.mkid.abID[StrRet.uOffset - SizeOf(PItemID.mkid.cb)];
    SetString(Result, Pstr, PItemID.mkid.cb - StrRet.uOffset);
    end;
  STRRET_WSTR: Result := StrRet.pOleStr;
  end;
end;


procedure TForm1.sbut_ListDeskTopClick(Sender: TObject);
var
DeskFolder, MyCompISF: IShellFolder;
NextId,  MyCompIDL: PItemIDList;
ShellMalloc: IMalloc;
EnumList: IENUMIDLIST;
IsThere: Cardinal;
Attri, Level: Cardinal;
Name1, Str1: String;
Code: Integer;
StrRet: TStrRet;
PStr: PChar;

procedure GetFolder(IShellF: IShellFolder; PItemID: PItemIDList);
var
NextId3: PItemIDList;
FolderISF2: IShellFolder;
FolderEList2: IENUMIDLIST;
Go1, Att1: Cardinal;
DirName: String;
begin
OleCheck(IShellF.BindToObject(PItemID, nil, IShellFolder, FolderISF2));
OleCheck(FolderISF2.EnumObjects(Application.Handle, SHCONTF_FOLDERS or SHCONTF_INCLUDEHIDDEN, FolderEList2));
while (FolderEList2.Next(1, NextId3, Go1)=S_OK) do
if Go1 > 0 then
  begin
  DirName := GetPItemName(FolderISF2, NextID3);
  ListBox1.Items.Add(DirName);
  Att1 := SFGAO_FILESYSANCESTOR;
  FolderISF2.GetAttributesOf(1, NextId3, Att1);
  if Att1 <> 0 then
  Inc(Level);
  if Level < 256 then
  GetFolder(FolderISF2, NextId3);
  ShellMalloc.Free(NextID3);
  end;
end;

begin
if (ShGetMalloc(ShellMalloc) = S_OK) and (ShellMalloc <> nil) then
  begin
  OleCheck(SHGetDesktopFolder(DeskFolder));
  OleCheck(DeskFolder.EnumObjects(Application.Handle, SHCONTF_FOLDERS , EnumList));
  SHGetSpecialFolderLocation(Form1.Handle, CSIDL_DRIVES, MyCompIDL);
  try
  ListBox1.Clear;
  ListBox1.Items.Add('Desktop');
  while (EnumList.Next(1, NextId, IsThere)=S_OK) do
      begin
      if IsThere > 0 then
        begin
        Level := 0;
        Name1 := GetPItemName(DeskFolder, NextID);
        if DeskFolder.CompareIDs(0, NextId, MyCompIDL) = 0 then
        ListBox1.Items.Add(Name1);
        ShellMalloc.Free(NextID);
        end;
      end; // while
  OleCheck(DeskFolder.BindToObject(MyCompIDL, nil, IShellFolder, MyCompISF));
  OleCheck(MyCompISF.EnumObjects(Application.Handle, SHCONTF_FOLDERS, EnumList));

  while (EnumList.Next(1, NextId, IsThere)=S_OK) do
      begin
      if IsThere > 0 then
        begin
        Name1 := GetPItemName(MyCompISF, NextID);
        Attri := SFGAO_FILESYSTEM;
        MyCompISF.GetAttributesOf(1, NextId, Attri);
        if Attri <> 0 then
          begin
          ListBox1.Items.Add(Name1);
          Level := 0;
          OleCheck(MyCompISF.GetDisplayNameOf(NextID, SHGDN_FORPARSING, StrRet));
          case StrRet.uType of
            STRRET_CSTR: SetString(Str1, StrRet.cStr, StrLen(StrRet.cStr));
            STRRET_OFFSET:
              begin
              Pstr := @NextID.mkid.abID[StrRet.uOffset - SizeOf(NextID.mkid.cb)];
              SetString(Str1, Pstr, NextID.mkid.cb - StrRet.uOffset);
              end;
            STRRET_WSTR: Str1 := StrRet.pOleStr;
            end;
          Code := GetFileAttributes(PChar(Str1));
          if (Code <> -1) and (FILE_ATTRIBUTE_DIRECTORY and Code <> 0) then
          GetFolder(MyCompISF, NextID);
          end;
        ShellMalloc.Free(NextID);
        end;
      end;
  finally
  ShellMalloc.Free(MyCompIDL);
  end;
  end;
end;


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
I hope you have lots of time to read the API Help for index "Shell's Namespace"
0
 

Author Comment

by:mdlittle
ID: 8178110
Thanks Slick812
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses
Course of the Month12 days, 10 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question