?
Solved

Win32 Shell API question

Posted on 1999-07-20
9
Medium Priority
?
1,389 Views
Last Modified: 2013-12-03
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?
0
Comment
Question by:bogie2
[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
9 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1403366
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
 
LVL 23

Expert Comment

by:chensu
ID: 1403367
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
 
LVL 4

Expert Comment

by:wylliker
ID: 1403368
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 23

Expert Comment

by:naveenkohli
ID: 1403369
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
 
LVL 23

Expert Comment

by:naveenkohli
ID: 1403370
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
 
LVL 1

Expert Comment

by:satishks060799
ID: 1403371
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
 

Author Comment

by:bogie2
ID: 1403372
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
 
LVL 1

Expert Comment

by:satishks060799
ID: 1403373
From DisplayName generating ITEMID will fail for SomeItem.
Ex : Network etc..
0
 
LVL 23

Accepted Solution

by:
naveenkohli earned 2400 total points
ID: 1403374
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

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
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: …

718 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