ShellItem

wraps the IShellItem interface and exposes methods that retrieve information about a Shell item.  IShellItem and IShellItem2 are the preferred representations of items in any new code.

Authors

License

Documentation

Requirements

AutoHotkeyAHK v2 alpha
OSWindows XP SP1 / Windows Server 2003 or higher
Base classesUnknown
Helper classesSIGDN, SFGAO, SICHINT
Summary
ShellItemwraps the IShellItem interface and exposes methods that retrieve information about a Shell item.
IIDThis is IID_IShellItem.
CLSIDThis is CLSID_ShellItem.
Constructor methods
FromAbsolutePathCreates and initializes a Shell item object from an absolute path.
FromKnownFolderCreates a Shell item object for a known folder.
FromRelativePathCreates and initializes a Shell item object from a relative parsing name.
IShellItem methods
BindToHandlerBinds to a handler for an item as specified by the handler ID value (BHID).
GetParentGets the parent of an IShellItem object.
GetDisplayNameGets the display name of the IShellItem object.
GetAttributesGets a requested set of attributes of the IShellItem object.
CompareCompares two IShellItem objects.

IID

This is IID_IShellItem.  It is required to create an instance.

CLSID

This is CLSID_ShellItem.  It is required to create an instance.

Constructor methods

FromAbsolutePath

FromAbsolutePath( path,  
bc : =  0)

Creates and initializes a Shell item object from an absolute path.

Parameters

STR paththe path to the directory or file to create an item for
[opt] IBindCtx bca raw interface pointer to an IBindCtx instance used to pass parameters as inputs and outputs to the parsing function.  These passed parameters are often specific to the data source and are documented by the data source owners.

Returns

ShellItem itemthe created instance

FromKnownFolder

FromKnownFolder( folder,  
user : =  0)

Creates a Shell item object for a known folder.

Parameters

GUID folderthe GUID of the known folder
[opt] HTOKEN userAn access token used to represent a particular user.  This parameter is usually ommited, in which case the function tries to access the current user’s instance of the folder.  However, you may need to assign a value to hToken for those folders that can have multiple users but are treated as belonging to a single user.  The most commonly used folder of this type is Documents.

Returns

ShellItem itemthe created item

Remarks

To call this function on public known folders, the caller must have Administrator privileges.

FromRelativePath

FromRelativePath( path,  
parent : =  0,
bc : =  0)

Creates and initializes a Shell item object from a relative parsing name.

Parameters

STR paththe relative path to the item
[opt] ShellItem parentthe item the path is relative to (either as ShellItem instance or raw interface pointer).  If this is empty, the current working directory is used.
[opt] IBindCtx bca raw interface pointer to an IBindCtx instance that controls the parsing operation.

Returns

ShellItem itemthe created item

Remarks

Currently, this only works if a parent item is supplied.

IShellItem methods

BindToHandler

BindToHandler( mode,  
 interface,  
bc : =  0)

Binds to a handler for an item as specified by the handler ID value (BHID).

Parameters

GUID modea GUID that specifies which handler will be created, either as GUID string or as pointer..  See Remarks.
IID interfacethe IID of the interface to retrieve, either as GUID string or as pointer.
[opt] IBindCtx bca raw interface pointer to an IBindCtx instance on a bind context object.  Used to pass optional parameters to the handler.  The contents of the bind context are handler-specific.  For example, when binding to BHID_Stream, the STGM flags in the bind context indicate the mode of access desired (read or read/write).

Returns

UPTR instancea raw memory pointer to the created instance

Remarks

The GUID for bc must be one of the following values defined in Shlguid.h: BHID_SFObject - Restricts usage to BindToObject.  BHID_SFUIObject - Restricts usage to GetUIObjectOf.  BHID_SFViewObject - Restricts usage to CreateViewObject.  BHID_Storage - Attempts to retrieve the storage RIID, but defaults to Shell implementation on failure.  BHID_Stream - Restricts usage to IStream.  BHID_LinkTargetItem - CLSID_ShellItem is initialized with the target of this item (can only be SFGAO.LINK).  See GetAttributesOf for a description of SFGAO.LINK.  BHID_StorageEnum - If the item is a folder, gets an IEnumShellItems object with which to enumerate the storage contents.  BHID_Transfer - Windows Vista and later: If the item is a folder, gets an ITransferSource or ITransferDestination object.  BHID_PropertyStore - Windows Vista and later: Restricts usage to IPropertyStore or IPropertyStoreFactory.  BHID_ThumbnailHandler - Windows Vista and later: Restricts usage to IExtractImage or IThumbnailProvider.  BHID_EnumItems - Windows Vista and later: If the item is a folder, gets an IEnumShellItems object that enumerates all items in the folder.  This includes folders, nonfolders, and hidden items.  BHID_DataObject - Windows Vista and later: Gets an IDataObject object for use with an item or an array of items.  BHID_AssociationArray - Windows Vista and later: Gets an IQueryAssociations object for use with an item or an array of items.  BHID_Filter - Windows Vista and later: Restricts usage to IFilter.  BHID_EnumAssocHandlers - Windows 7 and later: Retrieves an IEnumAssocHandlers that enumerates the association handlers for the given item.  Returns an enumeration of recommended handlers, similar to calling SHAssocEnumHandlers with ASSOC_FILTER_RECOMMENDED.

In AHK v2, you can currently not pass pointers for the mode and interface parameters.  Pass strings instead.

GetParent

GetParent()

Gets the parent of an IShellItem object.

Returns

ShellItem parentthe parent item

GetDisplayName

GetDisplayName(flag : =  0)

Gets the display name of the IShellItem object.

Parameters

[opt] INT flaga flag indicating how the name should look like.  You may use the fields of the SIGDN class for convenience.  Defaults to SIGDN.NORMALDISPLAY.

Returns

STR namethe item’s display name

GetAttributes

GetAttributes( requested,
byRef attr)

Gets a requested set of attributes of the IShellItem object.

Parameters

UINT requesteda combination of flags specifying the attributes requested.  You may use the fields of the SFGAO class for convenience.
byRef UINT attrreceives a combination of SFGAO flags specifying the attributes actually present.

Returns

BOOL matchtrue if all requested attributes are present, false otherwise (or if an error occured).

Compare

Compare( compareTo,  
hint : =  0)

Compares two IShellItem objects.

Parameters

ShellItem compareTothe IShellItem to compare this instance to, either as raw interface pointer or ShellItem instance
[opt] INT hinta flag indicating how to perform the comparison.  You may use the fields of the SICHINT class for convenience.  Defaults to SICHINT.DISPLAY.

Returns

INT resultthe result of the comparison.  If the two items are the same, this equals zero; if they are different the parameter is nonzero.
FromAbsolutePath( path,  
bc : =  0)
Creates and initializes a Shell item object from an absolute path.
FromKnownFolder( folder,  
user : =  0)
Creates a Shell item object for a known folder.
FromRelativePath( path,  
parent : =  0,
bc : =  0)
Creates and initializes a Shell item object from a relative parsing name.
BindToHandler( mode,  
 interface,  
bc : =  0)
Binds to a handler for an item as specified by the handler ID value (BHID).
GetParent()
Gets the parent of an IShellItem object.
GetDisplayName(flag : =  0)
Gets the display name of the IShellItem object.
GetAttributes( requested,
byRef attr)
Gets a requested set of attributes of the IShellItem object.
Compare( compareTo,  
hint : =  0)
Compares two IShellItem objects.