Win32 Shell API question

Hi everybody,

this is an absolutely tough question. Please answer only if you really know what
the Shell API is about. In fact, I will only give to grades on answers: A and F.

Now about the problem: It has to do with the Shell Name Space introduced with
Windows 95. Imagine I wanted to re-write the File-Open common dialog. I will
have to deal with ITEMIDLIST and IShellFolder and related stuff. But how?
Documentation is scarce.

For example, when I use IShellFolder::EnumObjects to query for subfolders of the
Desktop, I do not only get "My Computer", "Network Neighborhood" and "My Briefcase",
but also "Internet Explorer" and "Recycle Bin". Of course, in the File-Open common
dialog, the latter two don't appear. But how does Windows achieve this? I really
have a hard time finding out about all this. If I'd query for subfolders of
"My Computer", I'd probably get "Control Panel", "Printers", and so on. There are
quite a lot of different folder types in Win32. But I have absolutely no clue how
to distinguish between them.

Can you point out a good source of information on this? Or any other advise how
to achive what I outlined above?

Any ideas?
bogie2Asked:
Who is Participating?
 
naveenkohliConnect With a Mentor Commented:
You are right that there can be more than one folders having the sane display name. But if you save the complete path, then it is guranteed that it will be unique through out the shell space. And thats the propertyof PIDL too that it guarntees the uniqueness of a folder ID..
0
 
Tommy HuiEngineerCommented:
The idea is that you have to use IShellFolder::EnumObjects() to enumerate through the items. Start with SHGetDesktopFolder() to retrieve the root folder. Then use EnumObjects() to iterate through the top level items. On top of this, you will need to use IShellFolder::GetAttributes() to check what attributes the current item has.

For example, on my computer, checking the attributes of the items give:

My Computer FOLDER HASSUBFOLDER CONTENTSMASK
Internet Explorer FOLDER HASSUBFOLDER CONTENTSMASK
Network Neighborhood FOLDER HASSUBFOLDER CONTENTSMASK
Recycle Bin FOLDER
My Briefcase FOLDER

So if you only want "Recycle Bin" and "My Briefcase", you can use SFGAO_FOLDER as your mask to GetAttributes() to get the right folders.


0
 
chensuCommented:
I think IShellFolder::GetAttributesOf can tell you that.

SFGAO_FILESYSTEM  The specified folders or file objects are part of the file system (that is, they are files, directories, or root directories).
SFGAO_FILESYSANCESTOR  The specified folders contain one or more file system folders.
SFGAO_FOLDER  The specified items are folders.

See
http://msdn.microsoft.com/library/sdkdoc/shellcc/shell/ifaces/ishellfolder/GetAttributesOf.htm#IShellFolder_GetAttributesOf
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
wyllikerCommented:
The MSDN documentation may be a first stop.

The common explorer dialog probably uses EnumObjects in conjunction with GetAttributesOf.  The Flag SFGAO_FILESYSTEM
indicates that the object is part of the file system and not a special object.  Check out this function and see what you get back for Internet Explorer and the Recycle Bin, Control Panel, History Folder (IE), Fonts folder, etc.  There are other APIs that may be used but this might start you off.


IShellFolder::GetAttributesOf


HRESULT GetAttributesOf(
    UINT cidl,
    LPCITEMIDLIST *apidl,
    ULONG *rgfInOut
   );      

Retrieves the attributes of one or more file objects or subfolders.

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

cidl
    Number of file objects from which to retrieve attributes.

apidl

Address of an array of pointers to ITEMIDLIST structures, each of which uniquely identifies a file object relative to the parent folder. Each ITEMIDLIST structure must contain exactly one SHITEMID structure followed by a terminating zero.

rgfInOut
Address of a single ULONG value that, on entry, contains the attributes that the caller is requesting. On exit, this value contains the requested attributes that are common to all of the specified objects. Note that this is the address of a single ULONG value, not an array of ULONG values. The lists below describe the possible flags for this parameter.


A file object's capability flags may be zero or a combination of the following values:

SFGAO_CANCOPY
The specified file objects or folders can be copied (same value as the DROPEFFECT_COPY flag).

SFGAO_CANDELETE
The specified file objects or folders can be deleted.

SFGAO_CANLINK
It is possible to create shortcuts for the specified file objects or folders (same value as the DROPEFFECT_LINK flag).

SFGAO_CANMOVE
The specified file objects or folders can be moved (same value as the DROPEFFECT_MOVE flag).

SFGAO_CANRENAME
The specified file objects or folders can be renamed.

SFGAO_CAPABILITYMASK
Mask for the capability flags.

SFGAO_DROPTARGET
The specified file objects or folders are drop targets.

SFGAO_HASPROPSHEET
The specified file objects or folders have property sheets.


A file object's display attributes may be zero or a combination of the following values:

SFGAO_DISPLAYATTRMASK
Mask for the display attributes.

SFGAO_GHOSTED
The specified file objects or folders should be displayed using a ghosted icon.

SFGAO_LINK
The specified file objects are shortcuts.

SFGAO_READONLY
The specified file objects or folders are read-only.

SFGAO_SHARE
The specified folders are shared.


A file object's contents flags may be zero or a combination of the following values:

SFGAO_CONTENTSMASK
Mask for the contents attributes.

SFGAO_HASSUBFOLDER
The specified folders have subfolders (and are, therefore, expandable in the left pane of Windows Explorer).


A file object's miscellaneous attributes may be zero or a combination of the following values:

SFGAO_BROWSABLE
The specified items can be browsed in place.

SFGAO_COMPRESSED
The specified items are compressed.

SFGAO_FILESYSTEM
The specified folders or file objects are part of the file system (that is, they are files, directories, or root directories).

SFGAO_FILESYSANCESTOR
The specified folders contain one or more file system folders.

SFGAO_FOLDER
The specified items are folders.

SFGAO_NEWCONTENT
The objects contain new content.

SFGAO_NONENUMERATED
The items are nonenumerated items.

SFGAO_REMOVABLE
The specified file objects or folders are on removable media.

SFGAO_VALIDATE
Validate cached information. The shell will validate that the objects specified in apidl still exist and will not used cached information when retrieving the attributes. If one or more of the items specified in apidl no longer exist, this method will return an error code. If cidl is zero, the shell will discard all cached information for the shell folder. This is similar to doing a refresh of the folder.


You can optimize this operation by not returning unspecified flags

0
 
naveenkohliCommented:
Goto this URL, it has the answer to your question... complete implementation of some Shell API functins..

-------------------------------------------------------
Using the Shell Namespace To Get Network Computers, Printers and Recycle Bin Items

http://www.codeguru.com/shell/shell_namespace.shtml

------------------------------------------------------

And do goto the comments section, the code for getting control panel items has been posted in one of the comments :)

Cheers!
0
 
naveenkohliCommented:
And if you will need updated version of the source code in that artice, let me know. The code for getting the icons for control pannel items has been added in last couple of days which needs to be updated on codeguru site.
0
 
satishks060799Commented:
First level of browsing ( "My Computer", "Network Neighborhood" and "My Briefcase" ) this you know.

To get subfolder use "BindToObject" method.

To get more information about each item Use "SHGetDataFromIdList" method.

This will work fine. For getting information from this method I think it will take more time then a Day.

Documentation is not correct for the "SHGetDataFromIdList" you have to get from Debugging.



0
 
bogie2Author Commented:
thui: thanks for your answer. However, I did not want to GET "Recycle Bin", but AVOID it.

naavenkohli: thanks for your answer. It got me started, at least. You deserve the points, I think. Just one more thing: can I save an ITEMID (in order to remember
the last path a user chose) Or must I remember the DisplayName and then
generate the ITEMID from it? If the latter's the case, isn't that somewhat
ambiguous since several items may have the same DisplayName?


wylliker: thanks, but I read the online docu and it didn't help (not in the first place, at least). Now, I know that GetAttributesOf() is the key function, but it was really
naavenkohli's code that got me started.


statishks: thanks for your comment. I will try the function you mentioned.
All others, thanks as well.
0
 
satishks060799Commented:
From DisplayName generating ITEMID will fail for SomeItem.
Ex : Network etc..
0
All Courses

From novice to tech pro — start learning today.