?
Solved

Quick One! Windows XP Directory Structure

Posted on 2003-03-19
4
Medium Priority
?
150 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 34

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

762 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