ShellFolder Component

Properties   Methods   Events   Config Settings   Errors  

The ShellFolder class enables creating a virtual folder containing items in the Windows Shell.

Syntax

cbfsshell.ShellFolder

Remarks

The ShellFolder struct provides a simple way to create a virtual folder in the Windows Shell. The struct enables control over the folder contents, customizing columns within the virtual folder, managing individual item properties, and more.

The struct communicates with the Windows Shell through a proxy DLL that is loaded by Explorer in order to provide a custom region in the Windows Shell namespace. The set of modules included in this product is discussed in the Deployment Instructions.

Installation and Initialization

Set DisplayName and Location to the desired values and call Install to register the proxy DLL with the Windows Shell.

Installation should be done at least once before using the library on a new system, but may be done several times to update the values of the properties Attributes, DisplayName, IconLocation, Location, ProxyPath, and Scope.

In most cases, it is necessary to restart Windows File Explorer after installation to refresh the list of namespaces. The Windows File Explorer view option "Launch folder windows as a separate process" will run new shell views in a different process, scanning for extensions; when the option is enabled, it is not necessary to restart Windows File Explorer but you need to open a new Shell folder to see a newly installed virtual folder.

ShellFolder component = new ShellFolder(); component.DisplayName = "Sales Department"; component.Location = Constants.NS_LOCATION_DESKTOP; component.Install();

After installation, the root folder will be visible in Windows File Explorer but it will not be ready to handle user interation.

The next step is to call Initialize, which will perform the necessary operations to facilitate communication between the system and your code. Initialization only needs to be called once per application launch.

component.Initialize();

Activate

The application should call the Activate method to turn on the virtual folder. Folder events will fire that correspond to Windows Shell tasks that need to be handled. Some events are mandatory, while others are fired only when certain functionality is enabled.

component.Activate();

Items

Handle the ListItems event to add items to Windows File Explorer view. Call ListItem for each folder or non-folder item. This event will fire every time a folder identified by ParentId needs to be listed. Your code should make sure that ListItem method is called only when an item should be visible as a subitem of ParentId. Retrieving the data to represent is up to you, and how to fetch the data usually depends on the data source.

private void OnListItems(object sender, ShellFolderListItemsEventArgs e) { // Add a file item var itemId = "0"; // Use your own logic to identify, name, and describe the item var path = ""; // Set this to a path of a real file if desired var name = "MyItem.txt"; var size = 1000; var iconPath = ""; var iconIndex = 0; var attributes = Constants.SFGAO_HASPROPSHEET | Constants.SFGAO_STORAGE | Constants.SFGAO_STREAM; m_Folder.ListItem(e.TaskId, itemId, attributes, size, name, path, iconPath, iconIndex); // Add a folder item itemId = "1"; name = "MyFolder"; attributes = Constants.SFGAO_FOLDER | Constants.SFGAO_HASPROPSHEET | Constants.SFGAO_STORAGE | Constants.SFGAO_STREAM; m_Folder.ListItem(e.TaskId, itemId, attributes, size, name, path, iconPath, iconIndex); }

After the ListItems event returns, the folder will be populated with the listed items, and they will be accessible within Windows File Explorer.

Note: The items should be uniquely identified by your code, setting the ItemId parameter of the ListItem call. It is important to choose an identifier that makes sense to you, as the same identifier will be presented when subsequent operations are performed against your new item. Please see Shell Item Ids for more information.

Properties

Properties are name-value pairs that express metadata about the items. Handle the GetProperties event to store details for your items. Applications should call AddProperty for each property value that should be associated with a particular item. This event will fire together with ListItems to get property values for each item. The specified properties will be shown within Windows File Explorer and retrieved automatically without any additional steps required.

private void OnGetProperties(object sender, ShellFolderGetPropertiesEventArgs e) { var propertyId = 4; // An identifier for System.Author defined by MSFT var formatGUID = "{F29F85E0-4FF9-1068-AB91-08002B27B3D9}" var propertyType = Constants.PROP_TYPE_STRING; var numericValue = 0; // Set only for numeric properties var dateValue = DateTime.MinValue; // Set only for date properties var stringValue = "John Doe"; // Set only for string properties // Add an Author property to the item m_Folder.AddProperty(e.TaskId, formatGUID, propertyId, propertyType, numericValue, dateValue, stringValue); }

Note: Properties are displayed in the Properties dialog box for a folder or an item, or in additional columns when Windows File Explorer is set to the Details view mode. Choose from the existing list of Windows Properties or register your own property with the system by calling RegisterSchema once per application installation. Please see Property System for more details.

Columns

The struct allows customizing columns in Windows File Explorer view. Handle the GetColumns event, and if the given folder should have columns, call AddColumn once for each column. Your code should make sure that AddColumn is called only when a particular column should be added to the folder identified by ParentId. Your code should also ensure that one column is added for each custom property.

private void OnGetColumns(object sender, ShellFolderGetColumnsEventArgs e) { var propertyID = 4; // System.Author var formatGUID = "{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"; var flags = Constants.SHCOLSTATE_ONBYDEFAULT; var name = ""; // Set only if using a dynamic column var defaultWidth = 0; // Set only if using a dynamic column var viewFlags = 0; // Set only if using a dynamic column // Add an Author column to the folder m_Folder.AddColumn(e.TaskId, formatGUID, propertyID, flags, name, defaultWidth, viewFlags); }

After the AddColumn method is called, the property values that correspond to the newly added column will be visible in Windows File Explorer.

Note: Columns are linked either to predefined properties or properties that have been registered with the system by calling RegisterSchema once per application installation. Columns linked to custom properties are referred to as dynamic columns and are limited in their capabilities. Please see AddColumn for more information.

Item Information

The application should handle the GetItemId and GetItemInfo events to provide the struct with details about the items. These events are triggered when the system needs data which may be specific to your usage scenario. For example, the identifiers associated with each item are known only to your code.

private static void OnGetItemId(object sender, ShellFolderGetItemIdEventArgs e) { var displayName = e.DisplayName; // Get the item that should be identified e.ItemId = itemId; // Use your own logic to set the ItemId }

The struct will occasionally search for items and retrieve other data associated with the item separate from the identifier. This is done for caching reasons and to ensure that the system is updated with all the information it needs.

private void OnGetItemInfo(object sender, ShellFolderGetItemInfoEventArgs e) { var itemId = e.ItemId; // Get the item that should be described e.Size = size; // Use your own logic to set item information e.IconIndex = iconIndex; e.IconPath = iconPath; e.FileSystemPath = fileSystemPath; e.Attributes = attributes; e.DisplayName = displayName; }

Item Content

The struct will handle returning the contents of a file when the item is physical, meaning it contains a value in the FileSystemPath parameter to the ListItem method. No other steps are required in this case.

If no value is provided in FileSystemPath parameter, the struct will trigger the GetItemData event when the Windows Shell requests the contents of a non-folder item. An application should handle this event to return data to applications that read from the file identified by ItemId. private void OnGetItemData(object sender, ShellFolderGetItemDataEventArgs e) { // Return item content Array.Copy(content, e.Buffer, size); }

Please see Physical and Virtual Windows Shell Items for more information.

Deactivation and Uninstall

To stop handling requests, call the Deactivate method. Deactivation should be done when the application ceases to process requests from the Windows Shell, rendering the virtual folder inactive.

component.Deactivate();

To unregister the proxy DLL from the system, call the Uninstall method. This action removes the virtual folder and is usually performed during an application's uninstall routine.

component.Uninstall();

Physical and Virtual Windows Shell Items

ShellFolder supports two types of virtual Windows Shell items (both folders and non-folder items). Physical items are associated with files and directories on some drive and have a corresponding path within a filesystem. Virtual items are not associated with a filesystem path. Both virtual and physical items may exist in the same Windows Shell folder.

Physical Items and Folders

Physical items and folders are associated with a physical filesystem path (file or folder). When working with physical items:

  • The FileSystemPath parameter of the ListItem method must be set to a non-empty value that is a valid path to an existing file or directory. The struct does not validate the path, but using an invalid path may lead to unexpected side effects when such an item is used.
  • Many properties will be automatically computed from the associated physical file or directory.
  • File content can be modified.
  • Physical items benefit from better automatic Windows Shell integration. For instance, many third-party context menu handlers will add menu items to Windows Shell items that are backed by a physical file.
  • Physical items benefit from better usability with custom applications (e.g., Office, Notepad).

Note: When an application opens a physical item in your namespace, the user may want to save a file under a new name. The Shell then offers the filesystem directory that is a parent of a backing file as a default location for a Save As operation. If the data is then saved to that directory, the namespace extension does not get notified about creation of such a file (the writing of the data occurs on the filesystem level rather than via the Shell). If a namespace extension needs to know about such save operations, it may use the ShellNotify struct to monitor the directories that are exposed via the extension.

Physical Shell Items Options

The SFGAO flags associated with the physical items or folders will determine the behavior of the Shell in regard to these items. The flags for physical items are provided in the ListItem method, and the default flags are as follows.

The default flags for physical folders are as follows.

Virtual Items and Folders

Virtual items and folders are not associated with a physical path, and the item is completely virtual. When working with virtual items:

  • The FileSystemPath parameter of the ListItem method must be set to empty string.
  • Additional handling may be necessary (such as handling of the GetItemData event for files).
  • Item content cannot be modified. For instance a user will be able to open a virtual Excel "file", but will not be able to save changes to the same file.
  • Virtual items can support custom filenames including characters which are typically forbidden (e.g., < > :). This support can be helpful when displaying items from an external source.
  • All aspects of a virtual Windows Shell item, such as visibility, content, and properties, may vary according to the context (user account, time of day, language, etc.). For example, the same virtual PDF file with the exact same name may be displayed to all users, but the content of the file may differ each time a user opens it.

Virtual Shell Items Options

The SFGAO flags associated with virtual items or folders will determine the behavior of the Shell in regard to these items. The flags for virtual items are provided in the ListItem method, and the default flags are as follows.

The default flags for virtual folders are as follows.

Shell Item Ids

When a folder's contents are requested, the ListItems event fires. If a folder is not empty, a handler of this event should make one or more calls to the ListItem method to provide information about each item within the folder. When calling ListItem, the Id parameter must be set to a unique identifier. The process used to generate the Id value is outside the scope of the struct, but it is recommended that the Id be no longer than 64 characters and be comprised of alphanumeric characters.

The Id of the item should not change once it has been specified. When the directory is enumerated again, the same Id should be returned for the item. Additionally, the Id should not change across user sessions. If a shortcut to an item is created by the user, and that item's Id changes, the shortcut will become invalid.

The Id specified in the call to ListItem will be provided as a parameter in other events that fire when the item is accessed.

PIDLs

A PIDL (or an IDL) is a fundamental Windows Shell concept. At a high level, it is pretty simple, as it is just a value that represents a Windows Shell item in the Windows Shell Namespace. It is a bit like a full filesystem path for a physical file or folder, except that it is a binary object and not a string. The name "PIDL" and "IDL" can be used interchangeably. The leading P stands for pointer, the IDL stands for item identifier list, and PIDL generally refers to an IDL itself rather than the pointer to it.

The below information is provided as a general knowledge. Your application will deal with PIDLs only when they denote some Windows Shell items that are not necessarily a part of the Windows Shell namespace extension that you create. Such PIDLs can be used with the Windows Shell API if you decide to call it directly. When CBFS Shell exposes these PIDL values they will appear hex-encoded. If an application needs to call a shell function, it has to decode the PIDL before calling that function.

Just like a full filesystem path is a list of strings separated by the directory separator (on Windows, it is the \ (backslash) character), a PIDL is a list (L is for list) of Ids (identifiers). Unlike a filesystem path, though, a PIDL is binary, and Ids are separated by a special PIDL separator (two consecutive zero bytes).

Microsoft provides more details about PIDLs here Identifying Namespace Objects.

Windows Property System

The Windows property system is used to manage properties of items within the Windows Shell. Properties are used by the AddColumn and AddIconColumn methods to define which property values are present as columns in the Windows Shell. Columns are most often thought of when using the "Details View" in Explorer, however properties are also visible in other views, such as the "Properties" dialog box of an individual item.

A property must be registered in the system before it can be used by AddColumn or AddIconColumn. Many properties are predefined in Windows, however custom properties can also be added by creating a .propdesc file and calling RegisterSchema.

Property Format

Properties have specific characteristics which are used to define and use the property. Each property registered in the system, whether predefined or custom, follows these rules:

  • Is uniquely addressed by its PROPERTYKEY, which is a Windows-defined structure (composed of a GUID value and an int32 value).
  • Has a canonical human-readable name (e.g., System.ItemNameDisplay).
  • Has a schema description, which is specified using the XML format in a .propdesc file and expressed programmatically through the Windows-defined IPropertyDescription interface.

Each column is associated with a property, and by extension is also associated with a "PropertyKey" and its property definition. ShellFolder adds a column for the DisplayName property of all items automatically. Additional columns should be added using AddColumn and AddIconColumn.

Property values

When an item's properties are needed (for instance, during a directory listing), the GetProperties event fires. The AddProperty method should be called from within the GetProperties event hander once for each column to specify the property value for the specified item.

Adding Columns For Properties to a Folder

To add one or more columns that will display property values of items, handle the GetColumns event and from the event handler, call the AddColumn or AddIconColumn methods.

Properties Defined By Windows

The AddColumn and AddIconColumn methods may be used to add columns using existing predefined properties. Microsoft provides detailed information about Predefined Properties. Note that FormatIDs in Microsoft docs do not include curly brackets, whereas in the property definition schemas and in the code, curly brackets around the GUID must be present.

Custom Properties

To create a custom property, the property must first be defined in a .propdesc XML file. The RegisterSchema method is then used to register the custom property defined in the XML file. The UnregisterSchema method may be used to unregister a previously registered custom property.

The Microsoft documentation provides additional details on Creating Custom Properties and Understanding the Property Description Schema.

A sample property schema is provided in the next section for reference. Once the .propdesc XML file has been created, it can be registered and unregistered using code like:

// register a property schema from a .propdesc file path MyShellFolder.RegisterSchema("C:\\path\\to\\myproperty.propdesc"); ... // unregister a property schema from a .propdesc file path MyShellFolder.UnregisterSchema("C:\\path\\to\\myproperty.propdesc");

Registering and unregistering of properties requires write access to the HKEY_LOCAL_MACHINE registry hive. It is common to perform registration and unregistration during the installation and uninstallation of an application for this reason.

Sample Property Schema

A sample schema for registering a column with icons is provided below. Please see AddIconColumn for additional details.

<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/windows/2006/propertydescription" schemaVersion="1.0" > <propertyDescriptionList publisher="Callback Technologies" product="MyCoolApp"> <propertyDescription name="MyCoolApp.MyIconSource" formatID="{d9f69df5-01ef-4838-acb7-055012a678ca}" propID="4"> <searchInfo reIndexPatterns="" processReIndexPatternsImmediately="true" inInvertedIndex="false" isColumn="false"> </searchInfo> <typeInfo type="UInt32" isInnate="true" groupingRange="Enumerated" isViewable="true"> </typeInfo> <displayInfo displayType="Enumerated"> <enumeratedList> <enum name="None" value="0" text=""> </enum> <enum name="Ok" value="1" text="Ok"> <image res="%systemroot%\system32\imageres.dll,-1405"> </image> </enum> <enum name="Error" value="2" text="Error"> <image res="%systemroot%\system32\imageres.dll,-1402"> </image> </enum> <enum name="Warning" value="3" text="Warning"> <image res="%systemroot%\system32\imageres.dll,-1403"> </image> </enum> </enumeratedList> </displayInfo> <labelInfo label="Icon UI"> </labelInfo> </propertyDescription> <propertyDescription name="MyCoolApp.MyIconUI" formatID="{d9f69df5-01ef-4838-acb7-055012a678ca}" propID="3"> <searchInfo reIndexPatterns="" processReIndexPatternsImmediately="true" inInvertedIndex="false" isColumn="false"> </searchInfo> <typeInfo type="Blob" isInnate="true" isViewable="true"> </typeInfo> <labelInfo label="Icon"> </labelInfo> <displayInfo defaultColumnWidth="10"> <drawControl control="IconList"> </drawControl> </displayInfo> </propertyDescription> </propertyDescriptionList> </schema>

The example schema defines two custom properties:

  • MyCoolApp.MyIconUI which is a property of "Blob" type. This property defines a column of the folder view in Details mode.
  • MyCoolApp.MyIconSource, which is a property of UInt32 type. It describes which icons can be displayed and where the corresponding images are to be taken from. The example references Windows-provided images, but an application may reference any EXE, DLL, or another PE file with Win32 resources as a source. The syntax of references is the standard Win32 resource syntax, as follows: <path>,-<resource index>

An application may define any number of icon-rendered columns in a folder.

Multiple Root Folders

The struct uses a unique Id derived from the license to load a proxy DLL into Windows File Explorer and communicate with the Shell. Each license will allow for one virtual folder to be defined. Please contact support for additional details if multiple simultaneous root folders are required.

Troubleshooting

Following are some helpful resources for troubleshooting issues.

  • If you are developing your application and you stop and start repeatedly while keeping Explorer open, there may be a memory/cache issue regarding item icons or names. To avoid this situation, one should terminate all Windows File Explorer processes and restart Explorer.
  • If your folder is not visible, check the Attributes property. The SFGAO_HIDDEN attribute will hide the extension.
  • If your folder is not visible, make sure your folder is not Disallowed. To check this, you can make sure that your folder class Id (see FolderClassGUID) is not found in the below registry key.
    • HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Shell Extensions\Disallowed
    • HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Shell Extensions\Disallowed
    • HKEY_LOCAL_MACHINE\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Shell Extensions\Disallowed
  • If your folder is not visible, make sure your folder is not Blocked. To check this, you can make sure that your folder class Id (see FolderClassGUID) is not found in the below registry key.
    • HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked
    • HKEY_LOCAL_MACHINE\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked
  • If your folder is not visible, make sure your folder is Approved. To check this, you can make sure that your project is found in the below registry key.
    • HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved
  • If your folder is visible but does not respond to requests, this could be a UAC issue. If your application is running with administrator rights and UAC is disabled, try setting Scope to AllUsers before calling Install.
  • If your folder is visible but does not respond to requests, this could be an incomplete deployment issue. On 64-bit systems, be sure to deploy both the 64-bit and 32-bit native proxy DLL. To ARM systems, be sure to deploy all of the native proxy DLLs.
  • If your folder is not visible in Common Dialogs, unfortunately, there may not be a solution to this problem. Common Dialogs are hosted by an application's process and not Windows File Explorer. Each application can customize the dialog any way they want and prevent any folder from appearing.
  • If your items are not visible in Common Dialogs, the application may restrict the Common Dialog view to just filesystem items. In this case, your application would need to adapt its code to ensure that the folder and the items contained within the folder contain the attribute SFGAO_FILESYSTEM. Even if your extension is filesystem-compliant, some applications may still fail depending on how they are implemented.
  • If your folder is not responding in Common Dialogs, it may be an incomplete deployment issue. Some applications are compiled as 32-bit binaries and use dialogs in 32-bit as well. If the native proxy DLL for 32-bit is not included, the Common Dialog will not be able to reach your folder.
  • If you observe slow behavior, it may be that an excessive number of requests are calling your folder. Any third-party extensions or application present on the system can use your extension for various purposes so it is recommended to test on clean and updated systems to narrow down a cause.
  • If you observe slow behavior during copy-pasting or drag-n-drop of data (especially, in Microsoft Office applications), it may be the problem of the data source that includes large blocks of data in different formats. You can use various third-party tools to inspect the Clipboard contents or the contents of the dragged data to identify the formats, which contain large blocks of data in which your extension is not interested. Then, you can exclude the undesired formats (or just include the formats you are interested in) using the ExcludeClipboardFormats and IncludeClipboardFormats configuration settings respectively.
  • If you are seeing strange behavior not contained in this list, please reach out to us with a description of the problem, and we are happy to help. Our support team is available over email at support@callback.com

Property List


The following is the full list of the properties of the component with short descriptions. Click on the links for further details.

AttributesThis property describes various aspects of the topmost virtual folder behavior.
DisplayNameThis property specifies the name that the Windows Shell uses when it displays the Namespace Extension.
DragItemsCountThe number of records in the DragItem arrays.
DragItemContentPathContains an absolute name with path of a file with the data item's content.
DragItemDataContains the payload of data the item.
DragItemFileNameContains a file name of the data item.
DragItemFormatContains the number of the clipboard format.
DragItemFormatNameContains the name of the clipboard format.
DragItemIdContains an Id of the data item.
DragItemPIDLContains a PIDL of the data item.
IconLocationThis property specifies the full path to the file with the icon.
LocationThis property specifies where the extension is located in the Windows Shell Namespace.
ProxyPathThis property specifies the path to the native proxy DLL.
ScopeThis property specifies whether the class is registered for the current user or for all users.
SelectedItemsCountThe number of records in the SelectedItem arrays.
SelectedItemFileNameContains a file name of the selected item.
SelectedItemIdContains an Id of the selected item.
SelectedItemPIDLContains a PIDL of the selected item.

Method List


The following is the full list of the methods of the component with short descriptions. Click on the links for further details.

ActivateThis method tells the class to start handling the requests sent to the namespace extension.
AddColumnThis method is used to provide information about a text column during folder enumeration.
AddIconColumnThis method is used to provide information about a column of a folder with an icon during folder enumeration.
AddMenuItemThis method is used to add a menu item to a context menu.
AddPropertyThis method is used to provide a value of a property of an item during folder enumeration.
ConfigSets or retrieves a configuration setting.
DeactivateThis method tells the class to stop handling the requests sent to the namespace extension.
HideInfoBarThis method hides a previously shown information bar.
InitializeThis method initializes the core library.
InstallThis method registers Windows Shell folder information to the system.
ListItemThis method is used to provide information about an item during folder enumeration.
RefreshFolderThis method notifies the class and the Windows Shell that a folder or an item has changed.
RefreshItemThis method notifies the class and the Windows Shell that an item has changed.
RefreshViewThis method notifies the Windows Shell that item views must be refreshed.
RegisterSchemaThis method is used to register a property schema with the Windows Shell.
RemoveMenuItemThis method is used to remove an existing menu item from a context menu.
ShowInfoBarThis method shows an information bar for a folder.
UninstallThis method unregisters Windows Shell folder information from the system.
UnregisterSchemaThis method is used to unregister a property schema from the Windows Shell.

Event List


The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.

CompareItemsThis event is fired when the folder sorts items and needs to compare two items during sorting.
DeleteItemThis event is fired when an item is deleted.
DragThis event is fired when a drag operation starts or when an item is dragged over another item in the folder.
DropThis event is fired when a drag operation finishes with a drop over an item or folder or when the clipboard data is pasted into a folder.
ErrorThis event is fired if an unhandled error occurs during an event.
GetColumnsThis event is fired when columns of a folder need to be added.
GetDragDataThis event is fired when a drag operation has started and the class needs to collect data for the drag operation.
GetInfoBarThis event is fired to show an information bar for a folder that is about to be displayed.
GetInfoTipThis event is fired when the infotip of an item is about to be displayed.
GetItemDataThis event is fired when the Windows Shell is reading the contents of an item.
GetItemIdThis event is fired when the system needs the identifier of an item.
GetItemInfoThis event is fired when information about an item needs to be retrieved.
GetNameLimitsThis event is fired to collect information about naming constraints for items in a folder.
GetPropertiesThis event is fired when the properties of an item need to be listed.
InvokeMenuThis event is fired when an item of the context menu is invoked.
ListItemsThis event is fired when the contents of a folder are listed.
MergeMenuThis event is fired when a context menu is shown for one or more items.
MergeMenuBottomThis event is fired when a context menu is shown for one or more items.
MergeMenuTopThis event is fired when a context menu is shown for one or more items.
MoveItemThis event is fired when an item is moved.
RenameItemThis event is fired when an item is renamed.

Config Settings


The following is a list of config settings for the component with short descriptions. Click on the links for further details.

ExcludeClipboardFormatsThe comma-separated list of clipboard formats that the namespace extension wants to ignore during drag-n-drop and clipboard operations.
FireCompareItemsWhether to fire the CompareItems event.
FolderClassGUIDID of the folder class.
IncludeClipboardFormatsThe comma-separated list of clipboard formats that the namespace extension is interested in when handling drag-n-drop and clipboard operations.
IPCErrorTextThe error text that will be displayed alongside the Refresh button when the native proxy DLL in the Windows Shell cannot communicate with the server (and your process).
IPCFormatThe fixed name of the RPC endpoint.
IsInstalledSpecifies whether the installation was performed.
ProductGUIDID of the proxy DLL.
RefreshButtonTextThe text that will be displayed on the Refresh button in the Windows Shell folder.
ServerStartArgumentsThe arguments to pass with the command.
ServerStartCommandLineThe command line to run when the server is not available.
ServerStartOperationThe operation verb.
ServerStartShowOptionDefines how the application windows should be shown.
ServerStartTimeToWaitOptional time to wait before retrying RPC connection.
ServerStartWorkingDirectoryThe working directory.
BuildInfoInformation about the product's build.
LicenseInfoInformation about the current license.

Attributes Property (ShellFolder Component)

This property describes various aspects of the topmost virtual folder behavior.

Syntax

func (obj *ShellFolder) Attributes() (int64, error)
func (obj *ShellFolder) SetAttributes(value int64) error

Default Value

0xA0C00108

Remarks

This property specifies various options, related to the behavior of the topmost (root) virtual folder, created by the Windows Shell Namespace Extension. Set this property before calling the Install method.

The property should contain zero or more of the following flags, OR'd together:

SFGAO_CANCOPY0x00000001The specified items can be copied.

SFGAO_CANMOVE0x00000002The specified items can be moved.

SFGAO_CANLINK0x00000004Shortcuts can be created for the specified items.

If a namespace extension returns this attribute, a Create Shortcut entry with a default handler is added to the shortcut menu that is displayed during drag-and-drop operations. The extension can also implement its own handler for the link verb in place of the default. If the extension does so, it is responsible for creating the shortcut. A Create Shortcut item is also added to Windows File Explorer's File menu and to normal shortcut menus.

SFGAO_STORAGE0x00000008The specified items can be bound to an IStorage object.

Should not be changed if item content is used.

SFGAO_CANRENAME0x00000010The specified items can be renamed.

SFGAO_CANDELETE0x00000020The specified items can be deleted.

SFGAO_HASPROPSHEET0x00000040The specified items have property sheets.

SFGAO_DROPTARGET0x00000100The specified items are drop targets.

SFGAO_PLACEHOLDER0x00000800The specified items are not fully present and recalled on open or access.

SFGAO_SYSTEM0x00001000The specified items are system items.

SFGAO_ENCRYPTED0x00002000The specified items are encrypted and might require special presentation.

SFGAO_ISSLOW0x00004000Accessing the item (through IStream or other storage interfaces) is expected to be a slow operation.

Applications should avoid accessing items flagged with SFGAO_ISSLOW.

SFGAO_GHOSTED0x00008000The specified items are shown as dimmed and unavailable to the user.

SFGAO_LINK0x00010000The specified items are shortcuts.

SFGAO_SHARE0x00020000The specified objects are shared.

SFGAO_READONLY0x00040000The specified items are read-only.

In the case of folders, this means that new items cannot be created in those folders. This should not be confused with the behavior specified by the file Read-Only attribute.

SFGAO_HIDDEN0x00080000The item is hidden and should not be displayed unless the Show hidden files and folders option is enabled in Folder Settings.

ShellItem property: IsHidden.

SFGAO_NONENUMERATED0x00100000The items are non-enumerated items and should be hidden.

Should not be changed.

SFGAO_NEWCONTENT0x00200000The items contain new content, as defined by the particular application.

SFGAO_STREAM0x00400000Indicates that the item has a stream associated with it.

Should not be changed if item content is used. Default for items: true.

SFGAO_STORAGEANCESTOR0x00800000Children of this item are accessible through IStream or IStorage. Those children are flagged with SFGAO_STORAGE or SFGAO_STREAM.

Should not be changed if item content is used.

SFGAO_VALIDATE0x01000000When specified as input, SFGAO_VALIDATE instructs the folder to validate that the items contained in a folder or Windows Shell item array exist.

Should not be changed.

SFGAO_REMOVABLE0x02000000The specified items are on removable media or are themselves removable devices.

SFGAO_COMPRESSED0x04000000The specified items are compressed.

SFGAO_BROWSABLE0x08000000The specified items can be hosted inside a web browser or Explorer frame.

To be used with non-folder items.

SFGAO_FILESYSANCESTOR0x10000000The specified folders are either file system folders or contain at least one descendant (child, grandchild, or later) that is a file system (SFGAO_FILESYSTEM) folder.

This attribute is added automatically to folders that represent filesystem objects. If the root folder is expected to contain filesystem items, add this flag to the Attributes property of the ShellFolder struct.

SFGAO_FOLDER0x20000000The specified items are folders.

Should not be changed. In the ShellFolder struct, this flag is added or removed automatically depending on the value of the IsFolder parameter of the ListItem method.

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

The parsed names of the items can be assumed to be valid Win32 file system paths. These paths can be either UNC or drive-letter based.

This attribute is added automatically to folders and items that represent filesystem objects.

SFGAO_HASSUBFOLDER0x80000000The specified folders have subfolders.

The SFGAO_HASSUBFOLDER attribute is only advisory and might be returned by Windows Shell folder implementations even if they do not contain subfolders. Note, however, that the converse - failing to return SFGAO_HASSUBFOLDER - definitively states that the folder objects do not have subfolders. Returning SFGAO_HASSUBFOLDER is recommended whenever a significant amount of time is required to determine whether any subfolders exist. For example, the Windows Shell always returns SFGAO_HASSUBFOLDER when a folder is located on a network drive.

Already handled, but may be changed if needed (when the application can determine for sure that the folder is empty).

SFGAO_DEFAULT_ROOT0xA0C00108Default value for the namespace root folder.

This attribute is a combination of SFGAO_FOLDER, SFGAO_HASSUBFOLDER, SFGAO_STREAM, SFGAO_STORAGEANCESTOR, SFGAO_DROPTARGET, SFGAO_STORAGE, and is used to initialize the value of the Attributes property of ShellFolder.

If the root folder is expected to contain filesystem items, add the SFGAO_FILESYSANCESTOR flag to the set of flags.

A more detailed description of the attributes can be found in the dedicated MSDN topic.

The default value of 0xA0C00108 (SFGAO_DEFAULT_ROOT) is a combination of the following flags:

Data Type

int64

DisplayName Property (ShellFolder Component)

This property specifies the name that the Windows Shell uses when it displays the Namespace Extension.

Syntax

func (obj *ShellFolder) DisplayName() (string, error)
func (obj *ShellFolder) SetDisplayName(value string) error

Default Value

""

Remarks

This name is displayed by the Windows Shell and should be human-readable, as end users will recognize your Namespace Extension by this name.

Data Type

string

DragItemsCount Property (ShellFolder Component)

The number of records in the DragItem arrays.

Syntax

func (obj *ShellFolder) DragItemsCount() (int32, error)

Default Value

0

Remarks

This property controls the size of the following arrays:

The array indices start at 0 and end at DragItemsCount - 1.

This property is read-only.

Data Type

int32

DragItemContentPath Property (ShellFolder Component)

Contains an absolute name with path of a file with the data item's content.

Syntax

func (obj *ShellFolder) DragItemContentPath(DragItemIndex int32) (string, error)

Default Value

""

Remarks

Contains an absolute name with path of a file with the data item's content.

In some cases, CBFS Shell stores the data in temporary files. In this case, this field contains the path of a temporary file with data, while the FileName field contains the name of the file as set by the data source. When Format is 15 (CF_HDROP), this field contains the same path as FileName.

The DragItemIndex parameter specifies the index of the item in the array. The size of the array is controlled by the DragItemsCount property.

This property is read-only.

Data Type

string

DragItemData Property (ShellFolder Component)

Contains the payload of data the item.

Syntax

func (obj *ShellFolder) DragItemData(DragItemIndex int32) ([]byte, error)

Remarks

Contains the payload of data the item.

If the data item contains data payload (rather than a reference to some file or Windows Shell item), such data are accessible via this field. The field may also contain the binary data of a file or Windows Shell item, if the data source provided the data in such a form.

The DragItemIndex parameter specifies the index of the item in the array. The size of the array is controlled by the DragItemsCount property.

This property is read-only.

Data Type

[]byte

DragItemFileName Property (ShellFolder Component)

Contains a file name of the data item.

Syntax

func (obj *ShellFolder) DragItemFileName(DragItemIndex int32) (string, error)

Default Value

""

Remarks

Contains a file name of the data item.

If the data item contains a path to a file or folder or a PIDL of an item or folder that can be resolved to a filesystem path, this field contains the corresponding path.

If the data item carries some data payload with the associated file name, the Data field will be non-empty, and this FileName field will contain the file name associated with the payload.

In other cases, the field is empty.

The DragItemIndex parameter specifies the index of the item in the array. The size of the array is controlled by the DragItemsCount property.

This property is read-only.

Data Type

string

DragItemFormat Property (ShellFolder Component)

Contains the number of the clipboard format.

Syntax

func (obj *ShellFolder) DragItemFormat(DragItemIndex int32) (int32, error)

Default Value

0

Remarks

Contains the number of the clipboard format.

Data formats, in which data are stored during drag-n-drop and copy/paste operations, have numeric values - either assigned by the system (standard and registered formats) or private, defined by an application from the range dedicated for private formats. This field contains the format, in which the data item is represented.

The DragItemIndex parameter specifies the index of the item in the array. The size of the array is controlled by the DragItemsCount property.

This property is read-only.

Data Type

int32

DragItemFormatName Property (ShellFolder Component)

Contains the name of the clipboard format.

Syntax

func (obj *ShellFolder) DragItemFormatName(DragItemIndex int32) (string, error)

Default Value

""

Remarks

Contains the name of the clipboard format.

This field contains the name or a string identifier of the clipboard format, in which this data item is present. The field may be empty if the format doesn't have a text name/identifier. In such cases, an application should use the Format field with a numeric value of the format.

The DragItemIndex parameter specifies the index of the item in the array. The size of the array is controlled by the DragItemsCount property.

This property is read-only.

Data Type

string

DragItemId Property (ShellFolder Component)

Contains an Id of the data item.

Syntax

func (obj *ShellFolder) DragItemId(DragItemIndex int32) (string, error)

Default Value

""

Remarks

Contains an Id of the data item.

This field contains the Id of the data item. It may be empty if the data item is not a part of the virtual Windows Shell folder or its children.

The DragItemIndex parameter specifies the index of the item in the array. The size of the array is controlled by the DragItemsCount property.

This property is read-only.

Data Type

string

DragItemPIDL Property (ShellFolder Component)

Contains a PIDL of the data item.

Syntax

func (obj *ShellFolder) DragItemPIDL(DragItemIndex int32) ([]byte, error)

Remarks

Contains a PIDL of the data item.

This field contains the PIDL of an item if the data item is a Windows Shell item. If the data item is not a Windows Shell item, such as text or an image, then this property is null.

The DragItemIndex parameter specifies the index of the item in the array. The size of the array is controlled by the DragItemsCount property.

This property is read-only.

Data Type

[]byte

IconLocation Property (ShellFolder Component)

This property specifies the full path to the file with the icon.

Syntax

func (obj *ShellFolder) IconLocation() (string, error)
func (obj *ShellFolder) SetIconLocation(value string) error

Default Value

""

Remarks

This property specifies the full path to the file with the icon for the Windows Shell Namespace Extension. Set this before calling the Install method to add an icon to the virtual folder.

DLL and EXE Icon Resources

If the icon is contained in an EXE or DLL file, the path may be followed by a comma and an integer value. This may be either an ID or the index of the icon in the resources within the file. If the ID is used, it must be prefixed with a - character. For example:

<path\to\file.dll>,-<resource ID>

<path\to\file.dll>,<resource index>

Data Type

string

Location Property (ShellFolder Component)

This property specifies where the extension is located in the Windows Shell Namespace.

Syntax

func (obj *ShellFolder) Location() (string, error)
func (obj *ShellFolder) SetLocation(value string) error

Default Value

""

Remarks

This property describes where the Windows Shell Namespace Extension will be located in the Windows Shell Namespace. This should be set before calling the Install method.

This location must be one of the following specified values:

NS_LOCATION_NONENo location.

Used for extensions that implement "file as folder" feature and that may appear anywhere within the Windows Shell namespace.

NS_LOCATION_COMMONPLACESCommonPlacesAdd or Remove Programs Windows Shell folder or Programs and Features (Windows 10 and later).

Corresponds to FOLDERID_ChangeRemovePrograms well-known ID.

NS_LOCATION_CONTROLPANELControlPanelControl Panel folder.

Corresponds to FOLDERID_ControlPanelFolder well-known ID.

NS_LOCATION_DESKTOPDesktopDesktop folder and Desktop itself.

Corresponds to FOLDERID_Desktop well-known ID.

NS_LOCATION_FONTSFontsFolderFonts folder.

Corresponds to FOLDERID_Fonts well-known ID.

NS_LOCATION_MYCOMPUTERMyComputerMy Computer Windows Shell folder.

Corresponds to FOLDERID_ComputerFolder well-known ID.

NS_LOCATION_NETWORK_NEIGHBORHOODNetworkNeighborhoodNetwork Windows Shell folder.

Corresponds to FOLDERID_NetworkFolder well-known ID.

NS_LOCATION_ENTIRE_NETWORKNetworkNeighborhood\EntireNetworkNetwork Shortcuts folder.

Corresponds to FOLDERID_NetHood well-known ID.

NS_LOCATION_PRINTERS_AND_FAXESPrintersAndFaxesPrinters and Faxes folder or Devices and Printers (Windows 10 or later).

Corresponds to FOLDERID_PrintersFolder well-known ID.

NS_LOCATION_USERS_FILESUsersFilesUser's root folder.

Corresponds to FOLDERID_UsersFiles well-known ID.

NS_LOCATION_USERS_LIBRARIESUsersLibrariesLibraries folder.

Corresponds to FOLDERID_UsersLibraries well-known ID.

Additional information about well-known folder IDs can be found in the dedicated MSDN topic.

Data Type

string

ProxyPath Property (ShellFolder Component)

This property specifies the path to the native proxy DLL.

Syntax

func (obj *ShellFolder) ProxyPath() (string, error)
func (obj *ShellFolder) SetProxyPath(value string) error

Default Value

""

Remarks

This property may be used to specify the path to the native proxy DLL, which is loaded by the Windows Shell. The value may be in one of these formats:

  1. The name of the directory with Proxy DLLs. In this case, the struct will choose the first DLL with the appropriate architecture.
  2. The full path with the name of the DLL. In this case, just this DLL will be loaded.
  3. The full path with wildcards in the name part (a pattern). In this case, the struct will choose the first DLL that matches the passed pattern.

If left empty, the struct will automatically attempt to locate the appropriate DLL by searching the directory where the application's executable resides.

Data Type

string

Scope Property (ShellFolder Component)

This property specifies whether the class is registered for the current user or for all users.

Syntax

func (obj *ShellFolder) Scope() (int32, error)
func (obj *ShellFolder) SetScope(value int32) error

Default Value

1

Remarks

This property specifies whether the information related to the struct is written to the registry for the current user or for all users.

In the latter case, administrative rights are required to successfully execute the Install and Uninstall methods. If the user account of the process that calls these methods does not have such rights, the call will fail with an error.

Data Type

int32

SelectedItemsCount Property (ShellFolder Component)

The number of records in the SelectedItem arrays.

Syntax

func (obj *ShellFolder) SelectedItemsCount() (int32, error)

Default Value

0

Remarks

This property controls the size of the following arrays:

The array indices start at 0 and end at SelectedItemsCount - 1.

This property is read-only.

Data Type

int32

SelectedItemFileName Property (ShellFolder Component)

Contains a file name of the selected item.

Syntax

func (obj *ShellFolder) SelectedItemFileName(SelectedItemIndex int32) (string, error)

Default Value

""

Remarks

Contains a file name of the selected item.

If an item is a filesystem object and its PIDL can be resolved to a filesystem path, this field contains a full path on the filesystem; otherwise, the field is empty.

The SelectedItemIndex parameter specifies the index of the item in the array. The size of the array is controlled by the SelectedItemsCount property.

This property is read-only.

Data Type

string

SelectedItemId Property (ShellFolder Component)

Contains an Id of the selected item.

Syntax

func (obj *ShellFolder) SelectedItemId(SelectedItemIndex int32) (string, error)

Default Value

""

Remarks

Contains an Id of the selected item.

If a selected item comes from within the virtual Windows Shell folder managed by the ShellFolder struct, this field contans an application-defined Id. In other cases, this field is empty and the application may use the PIDL field to identify the item.

The SelectedItemIndex parameter specifies the index of the item in the array. The size of the array is controlled by the SelectedItemsCount property.

This property is read-only.

Data Type

string

SelectedItemPIDL Property (ShellFolder Component)

Contains a PIDL of the selected item.

Syntax

func (obj *ShellFolder) SelectedItemPIDL(SelectedItemIndex int32) ([]byte, error)

Remarks

Contains a PIDL of the selected item.

This field contains the PIDL of the selected item.

The SelectedItemIndex parameter specifies the index of the item in the array. The size of the array is controlled by the SelectedItemsCount property.

This property is read-only.

Data Type

[]byte

Activate Method (ShellFolder Component)

This method tells the class to start handling the requests sent to the namespace extension.

Syntax

func (obj *ShellFolder) Activate() error

Remarks

This method is used to tell the component to begin handling Windows Shell requests and start firing the corresponding events.

AddColumn Method (ShellFolder Component)

This method is used to provide information about a text column during folder enumeration.

Syntax

func (obj *ShellFolder) AddColumn(TaskId int32, FormatId string, PropertyId int32, Flags int32, Name string, DefaultWidth int32, ViewFlags int32) error

Remarks

This method provides the system with information about a text column of the folder referenced in the GetColumns event. This method should only be called from within the GetColumns event handler. To add an icon column, use AddIconColumn instead.

The TaskId parameter identifies the current operation. It should be set to the same value as the one received in the GetColumns event.

The FormatId parameter specifies the GUID of the property format. This acts as a broad identifier for a set of related properties and their corresponding columns. Its value must be specified in Registry Format. For instance: {1FAD0EF2-9A03-4B87-B4BC-645B7035ED90}.

The PropertyId parameter specifies the ID of the property. Its value is used to identify each property distinctly in a group that shares the same GUID.

The Flags parameter configures the behavior and display settings of the column. Its value may include one or more of the following SHCOLSTATE flags OR'd together. Note that some of these flags are only applicable to dynamic columns:

SHCOLSTATE_TYPE_STR0x00000001The value is displayed as a string.

Use with a dynamic column to specify the type of its data.

SHCOLSTATE_TYPE_INT0x00000002The value is displayed as an integer.

Use with a dynamic column to specify the type of its data.

SHCOLSTATE_TYPE_DATE0x00000003The value is displayed as a date.

Use with a dynamic column to specify the type of its data.

SHCOLSTATE_ONBYDEFAULT0x00000010The column should be visible by default in Details view.

If not set, the column will not be visible, which may be confusing for users.

SHCOLSTATE_SLOW0x00000020Will be slow to compute. Perform on a background thread.

SHCOLSTATE_HIDDEN0x00000100Not displayed in the UI.

SHCOLSTATE_NOSORTBYFOLDERNESS0x00000800When sorting by contents of this column, do not sort subfolders separately from non-folder items.

SHCOLSTATE_FIXED_WIDTH0x00001000Can't resize the column.

SHCOLSTATE_NODPISCALE0x00002000The width is the same in all dpi.

SHCOLSTATE_FIXED_RATIO0x00004000Fixed width and height ratio.

SHCOLSTATE_NO_GROUPBY0x00040000Grouping is disabled for this column.

The Name parameter specifies the visible text that identifies the column in Windows File Explorer. This value should be set to an empty string when adding columns for custom properties registered with the RegisterSchema method.

The DefaultWidth parameter determines the starting size of the column in Windows File Explorer.

The ViewFlags parameter is used to describe the column presentation and behavior of dynamic columns. This should be set to 0 when adding a column for a property that has been registered with RegisterSchema. Its value can have zero or more of the following flags OR'd together:

PDVF_CENTERALIGN0x00000001Content of the column cell should be centered.

PDVF_RIGHTALIGN0x00000002Content of the column cell should be aligned to the right.

PDVF_BEGINNEWGROUP0x00000004Show this property as the beginning of the next collection of properties in the view.

PDVF_FILLAREA0x00000008Fill the remainder of the view area with the content of this property.

PDVF_HIDELABEL0x00000200Hide the label of this property if the view normally shows the label.

PDVF_CANWRAP0x00001000The content of the column cell can be wrapped to the next row.

Dynamic Columns

Columns for custom properties that have not been registered with RegisterSchema are referred to as dynamic columns. Unlike columns that correspond to registered properties, dynamic columns are limited in their capabilities and do not carry any definition, schema, search information, or display information. The type of data they carry, along with their name, width, and visual properties, can only be specified by doing the following:

  • Provide a non-empty string in the Name parameter
  • Specify the default width of the column using DefaultWidth
  • Set the type of the data displayed in the column using the corresponding flag in the Flags parameter
  • Specify the column presentation and behavior using the ViewFlags parameter

AddIconColumn Method (ShellFolder Component)

This method is used to provide information about a column of a folder with an icon during folder enumeration.

Syntax

func (obj *ShellFolder) AddIconColumn(TaskId int32, IconSourceProperty string, IconUIProperty string) error

Remarks

This method provides the system with information about an icon column of the folder referenced in the GetColumns event. This method should only be called from within the GetColumns event handler. To add a text column, use AddColumn instead.

Before a column for icons can be added to a folder, a set of two properties must be registered in the Property System using the RegisterSchema method. The first property describes the set of icons the column can display, each associated with a numeric value. These values act as identifiers for the icons and can be used to specify the icon that will be displayed for a particular column by using the AddProperty method. It is important to note that an icon column is limited to displaying icons from this predefined set.

The second property describes the visual aspects of the column, such as its name and default width. For an example of how these two properties are defined, see the sample property schema Property System topic in the introduction section.

The TaskId parameter identifies the current operation. It should be set to the same value as the one received in the GetColumns event.

The IconSourceProperty parameter should be set to the value of the "name" attribute in the "propertyDescription" tag of the property that describes the set of icons the column can display. In the sample schema from the Property System topic, this value corresponds to MyCoolApp.MyIconSource.

The IconUIProperty parameter should be set to the value of the "name" attribute in the "propertyDescription" tag of the property that describes the visual aspects of the column. In the sample schema from the Property System topic, this value corresponds to MyCoolApp.MyIconUI.

AddMenuItem Method (ShellFolder Component)

This method is used to add a menu item to a context menu.

Syntax

func (obj *ShellFolder) AddMenuItem(TaskId int32, Verb string, ParentVerb string, Caption string, IsDefault bool, IsEnabled bool) error

Remarks

This method provides information to the system about a menu item to be appended to the context menu. This method should only be called from within the MergeMenu, MergeMenuTop, and MergeMenuBottom event handlers.

The TaskId parameter identifies the current operation. It should be set to the same value as the one received in the corresponding event.

The Verb parameter specifies the unique text identifier of the menu item. This is the value that identifies menu items in the InvokeMenu event.

The ParentVerb parameter is used to create submenus. If set to the verb of a menu item previously added with the AddMenuItem method, the new item will be added as a child under that item's submenu. Otherwise if ParentVerb is set to an empty string, the new menu item will appear at the top level of the context menu.

The Caption parameter is the visible text that represents the menu item in the context menu.

The IsDefault parameter marks the menu item as default. When set to true, the menu item will be invoked when a user double-clicks on an item in the virtual folder. Only one menu item can be marked as default in the context menu.

The IsEnabled parameter specifies the selectable state of a menu item. When set to true, the menu item will be active and selectable in the context menu. If set to false, the item will be unselectable and appear greyed-out in the context menu.

Naming Verbs

When naming verbs, it is recommended to use unique names to avoid collisions with other applications. Generic verb names such as open or edit may lead to issues because they may be used by the Windows Shell or other applications. Conversely, names such as OpenWithMyFineTool are more distinct and less likely to conflict.

Special Combinations

Setting Verb to an empty string and Caption to - will create a context menu separator.

Setting Caption to -> and Verb to Send To will create a "Send To" submenu that will be automatically populated by the Windows Shell.

AddProperty Method (ShellFolder Component)

This method is used to provide a value of a property of an item during folder enumeration.

Syntax

func (obj *ShellFolder) AddProperty(TaskId int32, FormatId string, PropertyId int32, PropType int32, NumericValue int64, DateValue time.Time, StringValue string) error

Remarks

This method provides the system with information about a property for an item referenced in the GetProperties event. This method should only be called from within the GetProperties event handler. When a folder is displayed as a table ("Details" view mode), and a column exists for the specified property type, the provided value of the item property is displayed in the corresponding column according to the column definition. Please refer to the Property System section for additional details.

The TaskId parameter identifies the current operation. It should be set to the same value as the one received in the GetProperties event.

The FormatId parameter specifies the GUID of the property format. This acts as a broad identifier for a set of related properties and their corresponding columns. Its value must be specified in Registry Format. For instance: {1FAD0EF2-9A03-4B87-B4BC-645B7035ED90}.

The PropertyId parameter specifies the ID of the property. Its value is used to identify each property distinctly in a group that shares the same GUID.

The PropType parameter specifies the data type of the value associated with the property. It should be set to one of the following:

PROP_TYPE_BOOL1Boolean

PROP_TYPE_LONG264-bit signed integer

PROP_TYPE_DATE3Date

PROP_TYPE_STRING4Text string

PROP_TYPE_ICON5Index of icon.

The index is used to choose the icon that will be displayed. The set of icons is defined in the property description (see AddIconColumn for details).

The NumericValue parameter specifies the value of the property depending on the value of PropType. If PropType is equal to PROP_TYPE_LONG, the value of the property will be set to the provided integer value. When PropType is set to PROP_TYPE_BOOL, the property's value will be true if NumericValue is a non-zero value, and false otherwise. In the case where PropType is set to PROP_TYPE_ICON, NumericValue indicates the index of an icon to display from a property description schema. In all other cases, its value is ignored.

The DateValue parameter specifies the date value of the property only when PropType is set to PROP_TYPE_DATE.

The StringValue parameter specifies the text value of the property only when PropType is set to PROP_TYPE_STRING.

Icon Columns

In order for an icon column to be displayed in a folder, a property must be added that specifies the icon that will be displayed for each item. To add this property, the following steps need to be taken:

  • Set the FormatId parameter to the value of the "formatID" attribute of the "propertyDescription" tag of the property that describes the visual representation of the column. In the sample schema from the Property System topic, this property is "MyCoolApp.MyIconUI", and FormatId would be set to {d9f69df5-01ef-4838-acb7-055012a678ca}.
  • Set the PropertyId parameter to the value of the "propID" attribute of the "propertyDescription" tag of the property that describes the visual representation of the column. In the sample schema from the Property System topic, this property is "MyCoolApp.MyIconUI", and PropertyId would be set to 3.
  • Set PropertyType to PROP_TYPE_ICON and set NumericValue to the index of the desired icon in the list of valid icons. This list is defined in a property schema, within the definition for a property that describes the set of icons that can be displayed. In the sample schema from the Property System topic, this property corresponds to "MyCoolApp.MyIconSource". In that case, NumericValue would be set to one of the values specified in the "value" attribute of the "enum" tags that correspond to that property.

Static Infotips

To set a static infotip for an item, the following two properties must be added. Alternatively, the infotip text can be provided dynamically by handling the GetInfoTip event.

FormatId: {c9944a21-a406-48fe-8225-aec7e24c211b} PropertyId: 4 PropType: PROP_TYPE_STRING
FormatId: {c9944a21-a406-48fe-8225-aec7e24c211b} PropertyId: 17 PropType: PROP_TYPE_STRING

Config Method (ShellFolder Component)

Sets or retrieves a configuration setting.

Syntax

func (obj *ShellFolder) Config(ConfigurationString string) (string, error)

Remarks

Config is a generic method available in every struct. It is used to set and retrieve configuration settings for the struct.

These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the struct, access to these internal properties is provided through the Config method.

To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.

Deactivate Method (ShellFolder Component)

This method tells the class to stop handling the requests sent to the namespace extension.

Syntax

func (obj *ShellFolder) Deactivate() error

Remarks

Use this method to stop handling requests that come from the Windows Shell via the native proxy DLL.

HideInfoBar Method (ShellFolder Component)

This method hides a previously shown information bar.

Syntax

func (obj *ShellFolder) HideInfoBar(FolderId string, InfoBarId string) error

Remarks

This method is used to hide an information bar previously shown using the ShowInfoBar method or the GetInfoBar event.

The FolderId parameter should be set to an Id of a folder for which the bar was shown.

The InfoBarId parameter should be set to the GUID that was associated with the information bar when it was shown.

Initialize Method (ShellFolder Component)

This method initializes the core library.

Syntax

func (obj *ShellFolder) Initialize() error

Remarks

This method initializes the core library and must be called each time the application starts before attempting to use other struct's methods. The two exceptions are Install and Uninstall, which don't require advance initialization.

If the application explicitly specifies the path to the proxy DLL, it should do this through the ProxyPath property before calling this method.

Install Method (ShellFolder Component)

This method registers Windows Shell folder information to the system.

Syntax

func (obj *ShellFolder) Install() error

Remarks

This method is used to install the proxy DLL that integrates with the Windows Shell and register folder information with the system.

Before calling this method, you may change the default values of the Attributes, DisplayName, IconLocation, Location, ProxyPath, and Scope properties. All of these values are used during installation and are placed in the Windows registry. Configuration settings, if used, also should be set using the Config method before the call to Install.

Registry Scope and User Permissions

The Scope property specifies whether the information is written to the registry for the current user or for all users.

In the latter case, administrative rights are required to execute this method successfully. If the user account of the process that calls this method does not have such rights, the call will fail with an ERROR_PRIVILEGE_NOT_HELD (0x0522) error.

ListItem Method (ShellFolder Component)

This method is used to provide information about an item during folder enumeration.

Syntax

func (obj *ShellFolder) ListItem(TaskId int32, Id string, Attributes int64, Size int64, DisplayName string, FileSystemPath string, IconPath string, IconIndex int32) error

Remarks

This method is used to provide the system with information about an item contained in the folder being listed. This method should only be called from within the ListItems event.

The TaskId parameter identifies the current operation. It should be set to the same value as the one received in the ListItems event.

The Id parameter should be set to the Id of the item or subfolder. This Id must be unique within the virtual filesystem represented by the struct.

The Attributes parameter specifies the attributes of the item. Use the SFGAO_FOLDER attribute to indicate that an item is a folder. Available attributes are:

SFGAO_CANCOPY0x00000001The specified items can be copied.

SFGAO_CANMOVE0x00000002The specified items can be moved.

SFGAO_CANLINK0x00000004Shortcuts can be created for the specified items.

If a namespace extension returns this attribute, a Create Shortcut entry with a default handler is added to the shortcut menu that is displayed during drag-and-drop operations. The extension can also implement its own handler for the link verb in place of the default. If the extension does so, it is responsible for creating the shortcut. A Create Shortcut item is also added to Windows File Explorer's File menu and to normal shortcut menus.

SFGAO_STORAGE0x00000008The specified items can be bound to an IStorage object.

Should not be changed if item content is used.

SFGAO_CANRENAME0x00000010The specified items can be renamed.

SFGAO_CANDELETE0x00000020The specified items can be deleted.

SFGAO_HASPROPSHEET0x00000040The specified items have property sheets.

SFGAO_DROPTARGET0x00000100The specified items are drop targets.

SFGAO_PLACEHOLDER0x00000800The specified items are not fully present and recalled on open or access.

SFGAO_SYSTEM0x00001000The specified items are system items.

SFGAO_ENCRYPTED0x00002000The specified items are encrypted and might require special presentation.

SFGAO_ISSLOW0x00004000Accessing the item (through IStream or other storage interfaces) is expected to be a slow operation.

Applications should avoid accessing items flagged with SFGAO_ISSLOW.

SFGAO_GHOSTED0x00008000The specified items are shown as dimmed and unavailable to the user.

SFGAO_LINK0x00010000The specified items are shortcuts.

SFGAO_SHARE0x00020000The specified objects are shared.

SFGAO_READONLY0x00040000The specified items are read-only.

In the case of folders, this means that new items cannot be created in those folders. This should not be confused with the behavior specified by the file Read-Only attribute.

SFGAO_HIDDEN0x00080000The item is hidden and should not be displayed unless the Show hidden files and folders option is enabled in Folder Settings.

ShellItem property: IsHidden.

SFGAO_NONENUMERATED0x00100000The items are non-enumerated items and should be hidden.

Should not be changed.

SFGAO_NEWCONTENT0x00200000The items contain new content, as defined by the particular application.

SFGAO_STREAM0x00400000Indicates that the item has a stream associated with it.

Should not be changed if item content is used. Default for items: true.

SFGAO_STORAGEANCESTOR0x00800000Children of this item are accessible through IStream or IStorage. Those children are flagged with SFGAO_STORAGE or SFGAO_STREAM.

Should not be changed if item content is used.

SFGAO_VALIDATE0x01000000When specified as input, SFGAO_VALIDATE instructs the folder to validate that the items contained in a folder or Windows Shell item array exist.

Should not be changed.

SFGAO_REMOVABLE0x02000000The specified items are on removable media or are themselves removable devices.

SFGAO_COMPRESSED0x04000000The specified items are compressed.

SFGAO_BROWSABLE0x08000000The specified items can be hosted inside a web browser or Explorer frame.

To be used with non-folder items.

SFGAO_FILESYSANCESTOR0x10000000The specified folders are either file system folders or contain at least one descendant (child, grandchild, or later) that is a file system (SFGAO_FILESYSTEM) folder.

This attribute is added automatically to folders that represent filesystem objects. If the root folder is expected to contain filesystem items, add this flag to the Attributes property of the ShellFolder struct.

SFGAO_FOLDER0x20000000The specified items are folders.

Should not be changed. In the ShellFolder struct, this flag is added or removed automatically depending on the value of the IsFolder parameter of the ListItem method.

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

The parsed names of the items can be assumed to be valid Win32 file system paths. These paths can be either UNC or drive-letter based.

This attribute is added automatically to folders and items that represent filesystem objects.

SFGAO_HASSUBFOLDER0x80000000The specified folders have subfolders.

The SFGAO_HASSUBFOLDER attribute is only advisory and might be returned by Windows Shell folder implementations even if they do not contain subfolders. Note, however, that the converse - failing to return SFGAO_HASSUBFOLDER - definitively states that the folder objects do not have subfolders. Returning SFGAO_HASSUBFOLDER is recommended whenever a significant amount of time is required to determine whether any subfolders exist. For example, the Windows Shell always returns SFGAO_HASSUBFOLDER when a folder is located on a network drive.

Already handled, but may be changed if needed (when the application can determine for sure that the folder is empty).

SFGAO_DEFAULT_ROOT0xA0C00108Default value for the namespace root folder.

This attribute is a combination of SFGAO_FOLDER, SFGAO_HASSUBFOLDER, SFGAO_STREAM, SFGAO_STORAGEANCESTOR, SFGAO_DROPTARGET, SFGAO_STORAGE, and is used to initialize the value of the Attributes property of ShellFolder.

The default values for Attributes of virtual items are listed below. This is only applicable when FileSystemPath is empty.

The default attributes for virtual folders are as follows.

The default values for Attributes of physical items are listed below. This is only applicable when FileSystemPath specifies the path to the file or folder on disk.

The default attributes for physical folders are as follows.

The Size parameter can be used to specify the size of the item data that one may copy. Set the value to -1 to tell the struct that an item has no data available for reading. When this value is set, GetItemData does not fire. The parameter is ignored for items with FileSystemPath set as well as for folders.

The DisplayName parameter specifies the human-readable name of the item. This may be the name of a file or directory represented by this item, or some other meaningful text for a user.

The FileSystemPath specifies the path to the file on disk if the item is a physical file and represents a file or directory on a filesystem. If the item is virtual and has no representation on a filesystem, pass an empty string for this parameter. See the Physical and Virtual Windows Shell Items topic in the introduction for additional information.

The IconPath parameter specifies the path to the DLL or EXE file that contains the icon for the item.

The IconIndex parameter determines which icon is displayed for the item. Its value may be either the index or Id of the specific icon within the resources of the DLL or EXE file in IconPath. Note that an index must be a positive number, while an Id value must be a negative number.

RefreshFolder Method (ShellFolder Component)

This method notifies the class and the Windows Shell that a folder or an item has changed.

Syntax

func (obj *ShellFolder) RefreshFolder(ItemId string, Action int32, NewId string, RefreshView int32) (bool, error)

Remarks

If a folder is modified by some means external to the Windows Shell, this method should be called to notify the Windows Shell and the struct about the change. Doing so prompts the Windows Shell to make any requests necessary to obtain the most up-to-date information, which in turn may fire the relevant struct events.

If an item or folder is added, this RefreshFolder method should be called for a parent folder (see details below).

ItemId specifies the Id of the folder that has changed. This is the Id that an application has previously provided when using the ListItem method to add a folder. When a new item or folder was or is about to be listed with the ListItem method, ItemId should be set to the Id of the new item's parent folder.

Action specifies the type(s) of change so that the OS knows what kind of information it needs to request. The value is a combination of the following flags:

UPDATE_TYPE_CREATE0x00000001A new item or folder is created.

This flag must be exclusive if used.

UPDATE_TYPE_CHANGE0x00000002An item or folder has been changed.

For folders, use this flag to tell the Windows Shell that the folder's contents have been changed.

UPDATE_TYPE_DELETE0x00000004An item or folder has been deleted.

UPDATE_TYPE_ATTRIBUTES0x00000008The attributes of an item or a folder have been updated.

UPDATE_TYPE_RENAME0x00000010An item was renamed; its name and possibly its Id have been changed.

This flag must be exclusive if used.

The NewId parameter is the Id of an item that has been newly created or renamed. When listing a new item using the ListItem method, NewId should be set to its new Id. Similarly if a folder is renamed and listed again, its Id will change. In this case, the NewId should be set to the new Id of the renamed folder. In all other cases, the value of NewId is ignored.

The RefreshView parameter tells the struct to request a refresh of related Windows Shell views. If a refresh is requested for the item that is not a folder, a parent folder is refreshed instead. The value can be one of the following:

REFRESH_VIEW_NO_REFRESH0Do not refresh anything

REFRESH_VIEW_ITEM1Refresh the item

REFRESH_VIEW_CHILDREN2Refresh views with the item and, if the item is a folder, views with the item's direct children.

REFRESH_VIEW_GRANDCHILDREN3Refresh views with the item and, if the item is a folder, views with the item's children and grandchildren (recursively).

Listing Multiple Items

When listing several children items in a batch with the ListItem method, it is recommended to first set RefreshView to REFRESH_VIEW_NO_REFRESH before the items are listed. Then, the RefreshView method should be called separately after all of the items have been reported.

RefreshItem Method (ShellFolder Component)

This method notifies the class and the Windows Shell that an item has changed.

Syntax

func (obj *ShellFolder) RefreshItem(ItemId string, Action int32, NewItemId string, RefreshView int32) (bool, error)

Remarks

If an item is modified by some means external to the Windows Shell, this method should be called to notify the Windows Shell and the struct about the change. Doing so prompts the Windows Shell to make any requests necessary to obtain the most up-to-date information, which in turn may fire the relevant struct events.

ItemId specifies the Id of the item that has changed. This is the Id that an application has previously provided when using the ListItem method to add an item.

Action specifies the type(s) of change so that the OS knows what kind of information it needs to request. The value is a combination of the following flags:

UPDATE_TYPE_CREATE0x00000001A new item or folder is created.

This flag must be exclusive if used.

UPDATE_TYPE_CHANGE0x00000002An item or folder has been changed.

For folders, use this flag to tell the Windows Shell that the folder's contents have been changed.

UPDATE_TYPE_DELETE0x00000004An item or folder has been deleted.

UPDATE_TYPE_ATTRIBUTES0x00000008The attributes of an item or a folder have been updated.

UPDATE_TYPE_RENAME0x00000010An item was renamed; its name and possibly its Id have been changed.

This flag must be exclusive if used.

The NewId parameter is the Id of a newly renamed item. When an item is renamed, its Id will change and its new Id should be passed into NewId.

The RefreshView parameter tells the struct to request a refresh of related Windows Shell views. If a refresh is requested for the item that is not a folder, a parent folder is refreshed instead. The value can be one of the following:

REFRESH_VIEW_NO_REFRESH0Do not refresh anything

REFRESH_VIEW_ITEM1Refresh the item

REFRESH_VIEW_CHILDREN2Refresh views with the item and, if the item is a folder, views with the item's direct children.

REFRESH_VIEW_GRANDCHILDREN3Refresh views with the item and, if the item is a folder, views with the item's children and grandchildren (recursively).

Listing Multiple Items

When listing several children items in a batch with the ListItem method, it is recommended to first set RefreshView to REFRESH_VIEW_NO_REFRESH before the items are listed. Then, the RefreshView method should be called separately after all of the items have been reported.

RefreshView Method (ShellFolder Component)

This method notifies the Windows Shell that item views must be refreshed.

Syntax

func (obj *ShellFolder) RefreshView(ItemId string, RefreshView int32) error

Remarks

If an item or folder is modified, an application may request a visual refresh of the folder views that are opened for the item identified by ItemId. If a refresh is requested for the item that is not a folder, a parent folder is refreshed instead.

The RefreshView parameter tells the struct to request a refresh of related Windows Shell views. The value can be one of the following:

REFRESH_VIEW_NO_REFRESH0Do not refresh anything

REFRESH_VIEW_ITEM1Refresh the item

REFRESH_VIEW_CHILDREN2Refresh views with the item and, if the item is a folder, views with the item's direct children.

REFRESH_VIEW_GRANDCHILDREN3Refresh views with the item and, if the item is a folder, views with the item's children and grandchildren (recursively).

RegisterSchema Method (ShellFolder Component)

This method is used to register a property schema with the Windows Shell.

Syntax

func (obj *ShellFolder) RegisterSchema(FileName string) error

Remarks

This method registers a property schema with the Windows Shell. This should normally be done once per application installation. Please refer to the Property System topic in the introduction section for additional details. To unregister the property schema, use UnregisterSchema.

The FileName parameter specifies the XML file with the property schema.

This method requires administrative rights to execute successfully. If the user account of the process that calls this method doesn't have such rights, the call will fail with an ERROR_PRIVILEGE_NOT_HELD (0x0522) error.

RemoveMenuItem Method (ShellFolder Component)

This method is used to remove an existing menu item from a context menu.

Syntax

func (obj *ShellFolder) RemoveMenuItem(TaskId int32, Verb string) error

Remarks

This method may be called from within MergeMenu, MergeMenuTop, and MergeMenuBottom event handlers to remove a menu item from a context menu.

The TaskId parameter identifies the current operation. It should be set to the same value as the one received in the corresponding event.

The Verb parameter is an identifier of the menu item to be removed and must be present in the ExistingVerbs list received by the event handler.

If an item has children (i.e., constitutes a submenu), the whole submenu gets removed.

ShowInfoBar Method (ShellFolder Component)

This method shows an information bar for a folder.

Syntax

func (obj *ShellFolder) ShowInfoBar(FolderId string, InfoBarId string, Text string) error

Remarks

This method displays an information bar for a folder at the top of Windows File Explorer view.

The FolderId parameter specifies the item Id of the folder for which the information bar will be displayed. If the folder specified by FolderId is not visible, the information bar will not be shown.

The InfoBarId parameter specifies the GUID of the information bar. This acts as an identifier that can be used to hide the bar later. If set to an empty value, the information bar will not be displayed. The GUID must be specified in Registry Format. For instance: {1FAD0EF2-9A03-4B87-B4BC-645B7035ED90}.

The Text parameter is the text content to be displayed in the information bar. If set to an empty value, the information bar will not be displayed.

Uninstall Method (ShellFolder Component)

This method unregisters Windows Shell folder information from the system.

Syntax

func (obj *ShellFolder) Uninstall() error

Remarks

This method is used to uninstall the native DLL that integrates with the Windows Shell from the system.

Before calling this method, you may change the default value of the Scope property.

Registry Scope and User Permissions

The Scope property specifies whether the information is written to the registry for the current user or for all users.

In the latter case, administrative rights are required to execute this method successfully. If the user account of the process that calls this method does not have such rights, the call will fail with an ERROR_PRIVILEGE_NOT_HELD (0x0522) error.

Handling Multiple Components

As ShellFolder and ShellMenu structs share a proxy DLL and a product GUID, they store some common information in a registry key. Calling the Uninstall method of one of the components will delete a shared registry key as well.

Each struct should be uninstalled properly by calling the corresponding Uninstall method. At the same time, if an application needs to uninstall just one struct and keep the other(s), it should call the Uninstall method of that struct and then call the Install method of the other structs to restore the common information in the shared registry key.

UnregisterSchema Method (ShellFolder Component)

This method is used to unregister a property schema from the Windows Shell.

Syntax

func (obj *ShellFolder) UnregisterSchema(FileName string) error

Remarks

This method unregisters a previously registered property schema from the Windows Shell. This should normally be done once per application deinstallation. Please refer to the Property System section for additional details.

The FileName parameter specifies the XML file with the property schema.

This method requires administrative rights to execute successfully. If the user account of the process that calls this method doesn't have such rights, the call will fail with an ERROR_PRIVILEGE_NOT_HELD (0x0522) error.

CompareItems Event (ShellFolder Component)

This event is fired when the folder sorts items and needs to compare two items during sorting.

Syntax

// ShellFolderCompareItemsEventArgs carries the ShellFolder CompareItems event's parameters.
type ShellFolderCompareItemsEventArgs struct {...}

func (args *ShellFolderCompareItemsEventArgs) Item1Id() string
func (args *ShellFolderCompareItemsEventArgs) Item2Id() string
func (args *ShellFolderCompareItemsEventArgs) ColumnFormatId() string
func (args *ShellFolderCompareItemsEventArgs) ColumnPropertyId() int32
func (args *ShellFolderCompareItemsEventArgs) Options() int32
func (args *ShellFolderCompareItemsEventArgs) Handled() bool
func (args *ShellFolderCompareItemsEventArgs) SetHandled(value bool)

func (args *ShellFolderCompareItemsEventArgs) Result() int32
func (args *ShellFolderCompareItemsEventArgs) SetResult(value int32)

// ShellFolderCompareItemsEvent defines the signature of the ShellFolder CompareItems event's handler function.
type ShellFolderCompareItemsEvent func(sender *ShellFolder, args *ShellFolderCompareItemsEventArgs)

func (obj *ShellFolder) GetOnCompareItemsHandler() ShellFolderCompareItemsEvent
func (obj *ShellFolder) SetOnCompareItemsHandler(handlerFunc ShellFolderCompareItemsEvent)

Remarks

This event fires when two items need to be compared during sorting. The event is useful for implementing custom sorting functionality that extends beyond the system's built-in comparison mechanism.

Note: This event will only fire when the FireCompareItems configuration setting is set to true.

The Item1Id and Item2Id parameters are Ids of the of the items that are being compared.

The ColumnFormatId and ColumnPropertyId parameters respectively specify the format ID and property ID of the column that is being sorted by. These values can be used to identify this column when the event is fired.

The Options parameter contains additional sorting options. Its value may be one of the following flags:

ICO_ALLFIELDS0x01All item properties should be compared

Compare all the information of the items. For instance, if the two items are files, the folder should compare their names, sizes, file times, attributes, and any other information in the items.

ICO_CANONICALONLY0x02Only item internal names should be compared.

When comparing by name, compare the system names but not the display names. When this flag is passed, the two items are compared by whatever criteria are the most efficient, as long as comparison is performed consistently. This flag is useful when comparing for equality or when the results of the sort are not displayed to the user. This flag cannot be combined with other flags.

The Result parameter indicates the outcome of the comparison. This value must be set to -1 to indicate that the first item precedes the second, to 0 to indicate that the items are equal, or to 1 to indicate that the second item precedes the first one.

The Handled parameter determines if the struct should use the value specified in Result to compare the two items the event was fired for. This value should be set to true to tell the struct to use the value specified in Result to compare the items. Set this to false to ignore the value specified in Result and use the system's built-in comparison mechanism instead. By default, this parameter is set to false.

DeleteItem Event (ShellFolder Component)

This event is fired when an item is deleted.

Syntax

// ShellFolderDeleteItemEventArgs carries the ShellFolder DeleteItem event's parameters.
type ShellFolderDeleteItemEventArgs struct {...}

func (args *ShellFolderDeleteItemEventArgs) ItemId() string
func (args *ShellFolderDeleteItemEventArgs) Recycle() bool
func (args *ShellFolderDeleteItemEventArgs) ResultCode() int32
func (args *ShellFolderDeleteItemEventArgs) SetResultCode(value int32)

// ShellFolderDeleteItemEvent defines the signature of the ShellFolder DeleteItem event's handler function.
type ShellFolderDeleteItemEvent func(sender *ShellFolder, args *ShellFolderDeleteItemEventArgs)

func (obj *ShellFolder) GetOnDeleteItemHandler() ShellFolderDeleteItemEvent
func (obj *ShellFolder) SetOnDeleteItemHandler(handlerFunc ShellFolderDeleteItemEvent)

Remarks

This event fires when an item is deleted.

The ItemId parameter is the item Id of the of the deleted item.

The Recycle parameter indicates that the item is being sent to the Recycle Bin. When set to true, it indicates that the item can be restored later.

The ResultCode parameter indicates the outcome of the event. By default, its value will always be 0. If the event cannot be handled successfully, its value can be set to an appropriate value to report an error. For example, if no item was found, set ResultCode to CBFSSHELL_ERR_FILE_NOT_FOUND.

Please refer to the Error Codes section for the set of possible values.

If an unhandled exception occurs within the event handler, the struct will catch it and report an internal error.

Drag Event (ShellFolder Component)

This event is fired when a drag operation starts or when an item is dragged over another item in the folder.

Syntax

// ShellFolderDragEventArgs carries the ShellFolder Drag event's parameters.
type ShellFolderDragEventArgs struct {...}

func (args *ShellFolderDragEventArgs) TaskId() int32
func (args *ShellFolderDragEventArgs) TargetId() string
func (args *ShellFolderDragEventArgs) DragType() int32
func (args *ShellFolderDragEventArgs) KeyState() int32
func (args *ShellFolderDragEventArgs) Effects() int32
func (args *ShellFolderDragEventArgs) SetEffects(value int32)

func (args *ShellFolderDragEventArgs) Formats() string
func (args *ShellFolderDragEventArgs) SetFormats(value string)

func (args *ShellFolderDragEventArgs) ResultCode() int32
func (args *ShellFolderDragEventArgs) SetResultCode(value int32)

// ShellFolderDragEvent defines the signature of the ShellFolder Drag event's handler function.
type ShellFolderDragEvent func(sender *ShellFolder, args *ShellFolderDragEventArgs)

func (obj *ShellFolder) GetOnDragHandler() ShellFolderDragEvent
func (obj *ShellFolder) SetOnDragHandler(handlerFunc ShellFolderDragEvent)

Remarks

This event is fired when a drag operation starts or when an item is dragged over another item in the virtual folder.

The TaskId parameter identifies the current operation. The DragData collection will contain the same set of items associated with the ongoing drag operation for each for each unique TaskId.

The TargetId parameter is the item Id of the drop target. This is the identifier of the item in the virtual folder that is underneath the dragged item. An empty TargetId indicates that the drop target is the root folder of the Windows Shell Namespace branch.

The DragType parameter indicates the type of drag operation being performed. Its value can be the one of the following:

DRAG_TYPE_ENTER0Cursor entered the folder

DRAG_TYPE_OVER1Cursor is moving over the folder

DRAG_TYPE_LEAVE2Cursor is leaving the folder

DRAG_TYPE_START5A drag operation has been initiated in the folder.

The KeyState parameter contains the current state of the modifier keys on the keyboard. Its value is not available when DragType is equal to DRAG_TYPE_START. Possible values can be a combination of any of these flags:

KEY_STATE_MK_LBUTTON0x00000001Left mouse button

KEY_STATE_MK_RBUTTON0x00000002Right mouse button

KEY_STATE_MK_MBUTTON0x00000010Middle mouse button

KEY_STATE_MK_SHIFT0x00000004Shift keyboard key

KEY_STATE_MK_CONTROL0x00000008Control keyboard key

KEY_STATE_MK_ALT0x00000020Alt keyboard key

The Effects parameter specifies the operations that are available to the user performing the drag operation. The parameter can be modified to change these operations only when DragType is not equal to DRAG_TYPE_LEAVE. Its value is a combination of the following flags, OR'd together:

DROP_EFFECT_NONE0x00000000The drop target does not accept the data

DROP_EFFECT_COPY0x00000001The data from the drag source is copied to the drop target.

DROP_EFFECT_MOVE0x00000002The data from the drag source is moved to the drop target.

DROP_EFFECT_LINK0x00000004The data from the drag source is linked to the drop target.

DROP_EFFECT_SCROLL-2147483648Scrolling is occurring in the target.

This is a supplementary flag that has a binary value 0x80000000.

The value may also include the highest bit set (the mask would be 0x80000000) which indicates that scrolling is occuring at the moment.

The Formats parameter contains the data formats in which the drag data is available to the target of the operation. The parameter can be used to determine how the target can handle the drag data. Its value is a list of text strings that represent different data formats, with each format separated by the LF character (numeric code 10). Possible formats may include the known formats listed below, or some other format values defined by the source of the operation.

DATA_FORMAT_CF_HDROPCF_HDROPStandard CF_HDROP format (clipboard format Id 15).

Elements of the DragData collection with this type contain Unicode file paths.

DATA_FORMAT_CF_BITMAPCF_BITMAPStandard CF_BITMAP format (clipboard format Id 2).

DATA_FORMAT_CF_TEXTCF_TEXTStandard CF_TEXT format (clipboard format Id 1).

DATA_FORMAT_CF_UNICODETEXTCF_UNICODETEXTStandard CF_UNICODETEXT format (clipboard format Id 13).

DATA_FORMAT_CF_RTFRich Text FormatText in RTF format

DATA_FORMAT_CFSTR_SHELLIDLISTShell IDList ArrayArray of Windows Shell Id lists.

An element of the DragData collection with this type contains a PIDL. If the PIDL can be resolved to a filename, the corresponding field will also be non-empty.

DATA_FORMAT_CFSTR_FILENAMEAFileNameA file name in system-default (8-bit CP_ACP or UTF8) format.

DATA_FORMAT_CFSTR_FILENAMEWFileNameWA file name in Unicode (UTF16) format

DATA_FORMAT_CFSTR_INETURLAUniformResourceLocatorA URL in system-default (8-bit CP_ACP or UTF8) format.

DATA_FORMAT_CFSTR_INETURLWUniformResourceLocatorWA URL in Unicode (UTF16) format.

DATA_FORMAT_CFSTR_FILEDESCRIPTORAFileGroupDescriptorFiles with binary data included.

Each element of the DragData collection with this type contains a filename with data.

DATA_FORMAT_CFSTR_FILEDESCRIPTORWFileGroupDescriptorWFiles with binary data included.

Each element of the DragData collection with this type contains a filename with data.

The ResultCode parameter indicates the outcome of the event. By default, its value will always be 0. If the event cannot be handled successfully, its value can be set to an appropriate value to report an error. For example, if no item was found, set ResultCode to CBFSSHELL_ERR_FILE_NOT_FOUND.

Please refer to the Error Codes section for the set of possible values.

If an unhandled exception occurs within the event handler, the struct will catch it and report an internal error.

Drag Data

When the event is fired and the DragType is either DRAG_TYPE_ENTER or DRAG_TYPE_OVER, an application will be able to access the data associated with the drag operation through the DragData collection. In these cases, the list of formats in which this data is available will be accessible via the Formats parameter.

If the event is fired and the DragType is DRAG_TYPE_START, the application will be responsible for defining the formats in which it can provide this data. To do this, it should populate the Formats parameter with the clipboard format Ids or registered names (an Id is recommended) of each intended format as a string, where each format is separated with the LF character (numeric code 10). Following this, the GetDragData event will fire right after this one to collect the data of the ongoing drag operation for each of the formats specified in the Formats parameter.

Drag Data Formats

In Windows, data formats used in clipboard or drag-and-drop operations are identified with unique numeric codes known as clipboard format Ids. Along with these Ids, formats may also be identified with a text identifier known as a clipboard format name. These identifiers can represent either predefined data formats recognized by the system, or custom data formats defined by third-party applications. More information about these formats can be found in the MSDN topic for Clipboard Formats.

When the event fires and the struct populates the contents of the Formats parameter, the formats listed may be represented with either types of identifiers. Additionally, the Format and FormatName properties of the elements in DragData collection will be automatically populated by the struct depending on the available identifiers for each of the listed formats. If a given format has a clipboard format name, the Formats parameter will contain its format name, and the FormatName field of the corresponding DragItem element will be set. If the format also has a clipboard format Id, the Format field of the corresponding DragItem element will be set to a non-zero value. Finally, if the format only has a clipboard format Id, its value will be used to represent the format in the Formats parameter. In this case, the Format field of the corresponding DragItem element will be set, while its FormatName field will be empty.

Drop Event (ShellFolder Component)

This event is fired when a drag operation finishes with a drop over an item or folder or when the clipboard data is pasted into a folder.

Syntax

// ShellFolderDropEventArgs carries the ShellFolder Drop event's parameters.
type ShellFolderDropEventArgs struct {...}

func (args *ShellFolderDropEventArgs) TaskId() int32
func (args *ShellFolderDropEventArgs) TargetId() string
func (args *ShellFolderDropEventArgs) KeyState() int32
func (args *ShellFolderDropEventArgs) Effects() int32
func (args *ShellFolderDropEventArgs) SetEffects(value int32)

func (args *ShellFolderDropEventArgs) Formats() string
func (args *ShellFolderDropEventArgs) ResultCode() int32
func (args *ShellFolderDropEventArgs) SetResultCode(value int32)

// ShellFolderDropEvent defines the signature of the ShellFolder Drop event's handler function.
type ShellFolderDropEvent func(sender *ShellFolder, args *ShellFolderDropEventArgs)

func (obj *ShellFolder) GetOnDropHandler() ShellFolderDropEvent
func (obj *ShellFolder) SetOnDropHandler(handlerFunc ShellFolderDropEvent)

Remarks

This event is fired when a drag operation finishes with a drop over an item inside the virtual folder. The event also fires when clipboard data is pasted into the virtual folder.

The TaskId parameter identifies the current operation. During the drag operation identified by the same TaskId, the DragData collection contains the same data items, associated with this drag operation.

The TargetId parameter is the item Id of the drop target. This is the identifier of the item in the virtual folder underneath the dragged item when it was dropped. An empty TargetId indicates that the drop target is the root folder of the Windows Shell Namespace branch.

The KeyState parameter contains the current state of the modifier keys on the keyboard. Possible values can be a combination of any of these flags:

KEY_STATE_MK_LBUTTON0x00000001Left mouse button

KEY_STATE_MK_RBUTTON0x00000002Right mouse button

KEY_STATE_MK_MBUTTON0x00000010Middle mouse button

KEY_STATE_MK_SHIFT0x00000004Shift keyboard key

KEY_STATE_MK_CONTROL0x00000008Control keyboard key

KEY_STATE_MK_ALT0x00000020Alt keyboard key

The Effects parameter specifies the operations that are available to the user performing the drag operation. The parameter can be modified to change the allowed operations for the current drag operation. Its value is a combination of the following flags, OR'd together:

DROP_EFFECT_NONE0x00000000The drop target does not accept the data

DROP_EFFECT_COPY0x00000001The data from the drag source is copied to the drop target.

DROP_EFFECT_MOVE0x00000002The data from the drag source is moved to the drop target.

DROP_EFFECT_LINK0x00000004The data from the drag source is linked to the drop target.

DROP_EFFECT_SCROLL-2147483648Scrolling is occurring in the target.

This is a supplementary flag that has a binary value 0x80000000.

The value may also include the highest bit set (the mask would be 0x80000000) which indicates that scrolling is occuring at the moment.

The Formats parameter contains the data formats in which the drag data is available to the target of the operation. The parameter can be used to determine how the target can handle the drag data. Its value is a list of text strings that represent different data formats, with each format separated by the LF character (numeric code 10). Possible formats may include the known formats listed below, or some other format values defined by the source of the operation.

DATA_FORMAT_CF_HDROPCF_HDROPStandard CF_HDROP format (clipboard format Id 15).

Elements of the DragData collection with this type contain Unicode file paths.

DATA_FORMAT_CF_BITMAPCF_BITMAPStandard CF_BITMAP format (clipboard format Id 2).

DATA_FORMAT_CF_TEXTCF_TEXTStandard CF_TEXT format (clipboard format Id 1).

DATA_FORMAT_CF_UNICODETEXTCF_UNICODETEXTStandard CF_UNICODETEXT format (clipboard format Id 13).

DATA_FORMAT_CF_RTFRich Text FormatText in RTF format

DATA_FORMAT_CFSTR_SHELLIDLISTShell IDList ArrayArray of Windows Shell Id lists.

An element of the DragData collection with this type contains a PIDL. If the PIDL can be resolved to a filename, the corresponding field will also be non-empty.

DATA_FORMAT_CFSTR_FILENAMEAFileNameA file name in system-default (8-bit CP_ACP or UTF8) format.

DATA_FORMAT_CFSTR_FILENAMEWFileNameWA file name in Unicode (UTF16) format

DATA_FORMAT_CFSTR_INETURLAUniformResourceLocatorA URL in system-default (8-bit CP_ACP or UTF8) format.

DATA_FORMAT_CFSTR_INETURLWUniformResourceLocatorWA URL in Unicode (UTF16) format.

DATA_FORMAT_CFSTR_FILEDESCRIPTORAFileGroupDescriptorFiles with binary data included.

Each element of the DragData collection with this type contains a filename with data.

DATA_FORMAT_CFSTR_FILEDESCRIPTORWFileGroupDescriptorWFiles with binary data included.

Each element of the DragData collection with this type contains a filename with data.

The ResultCode parameter indicates the outcome of the event. By default, its value will always be 0. If the event cannot be handled successfully, its value can be set to an appropriate value to report an error. For example, if no item was found, set ResultCode to CBFSSHELL_ERR_FILE_NOT_FOUND.

Please refer to the Error Codes section for the set of possible values.

If an unhandled exception occurs within the event handler, the struct will catch it and report an internal error.

Drag Data Formats

In Windows, data formats used in clipboard or drag-and-drop operations are identified with unique numeric codes known as clipboard format Ids. Along with these Ids, formats may also be identified with a text identifier known as a clipboard format name. These identifiers can represent either predefined data formats recognized by the system, or custom data formats defined by third-party applications. More information about these formats can be found in the MSDN topic for Clipboard Formats.

When the event fires and the struct populates the contents of the Formats parameter, the formats listed may be represented with either types of identifiers. Additionally, the Format and FormatName properties of the elements in DragData collection will be automatically populated by the struct depending on the available identifiers for each of the listed formats. If a given format has a clipboard format name, the Formats parameter will contain its format name, and the FormatName field of the corresponding DragItem element will be set. If the format also has a clipboard format Id, the Format field of the corresponding DragItem element will be set to a non-zero value. Finally, if the format only has a clipboard format Id, its value will be used to represent the format in the Formats parameter. In this case, the Format field of the corresponding DragItem element will be set, while its FormatName field will be empty.

Error Event (ShellFolder Component)

This event is fired if an unhandled error occurs during an event.

Syntax

// ShellFolderErrorEventArgs carries the ShellFolder Error event's parameters.
type ShellFolderErrorEventArgs struct {...}

func (args *ShellFolderErrorEventArgs) ErrorCode() int32
func (args *ShellFolderErrorEventArgs) Description() string
// ShellFolderErrorEvent defines the signature of the ShellFolder Error event's handler function.
type ShellFolderErrorEvent func(sender *ShellFolder, args *ShellFolderErrorEventArgs)

func (obj *ShellFolder) GetOnErrorHandler() ShellFolderErrorEvent
func (obj *ShellFolder) SetOnErrorHandler(handlerFunc ShellFolderErrorEvent)

Remarks

This event fires if an unhandled error occurs. Developers can use this information to track down unhandled errors that occur in the struct.

ErrorCode contains an error code and Description contains a textual description of the error.

GetColumns Event (ShellFolder Component)

This event is fired when columns of a folder need to be added.

Syntax

// ShellFolderGetColumnsEventArgs carries the ShellFolder GetColumns event's parameters.
type ShellFolderGetColumnsEventArgs struct {...}

func (args *ShellFolderGetColumnsEventArgs) TaskId() int32
func (args *ShellFolderGetColumnsEventArgs) FolderId() string
func (args *ShellFolderGetColumnsEventArgs) ResultCode() int32
func (args *ShellFolderGetColumnsEventArgs) SetResultCode(value int32)

// ShellFolderGetColumnsEvent defines the signature of the ShellFolder GetColumns event's handler function.
type ShellFolderGetColumnsEvent func(sender *ShellFolder, args *ShellFolderGetColumnsEventArgs)

func (obj *ShellFolder) GetOnGetColumnsHandler() ShellFolderGetColumnsEvent
func (obj *ShellFolder) SetOnGetColumnsHandler(handlerFunc ShellFolderGetColumnsEvent)

Remarks

This event is fired when the system requests information about a folder's columns. An event handler for this event determines the columns that are included in the folder. These are added by calling either one of the AddColumn or AddIconColumn methods from within the handler.

Note: The struct automatically adds a display name column and a column for item icons by default.

The event is fired when items are enumerated using the ListItems event, for each listed folder, right after all items have been reported and after GetProperties was fired for the folder identified by FolderId. For the root folder, the event is fired when the struct is activated using the Activate method.

The TaskId parameter identifies the current operation. Its value is required when calling the AddColumn method.

The FolderId parameter contains the item Id of the folder for which column information is being requested. An empty value for FolderId denotes the root folder of the Windows Shell Namespace branch.

The ResultCode parameter indicates the outcome of the event. By default, its value will always be 0. If the event cannot be handled successfully, its value can be set to an appropriate value to report an error. For example, if no item was found, set ResultCode to CBFSSHELL_ERR_FILE_NOT_FOUND.

Please refer to the Error Codes section for the set of possible values.

If an unhandled exception occurs within the event handler, the struct will catch it and report an internal error.

GetDragData Event (ShellFolder Component)

This event is fired when a drag operation has started and the class needs to collect data for the drag operation.

Syntax

// ShellFolderGetDragDataEventArgs carries the ShellFolder GetDragData event's parameters.
type ShellFolderGetDragDataEventArgs struct {...}

func (args *ShellFolderGetDragDataEventArgs) TaskId() int32
func (args *ShellFolderGetDragDataEventArgs) Format() int32
func (args *ShellFolderGetDragDataEventArgs) Buffer() []byte
func (args *ShellFolderGetDragDataEventArgs) BytesToRead() int32
func (args *ShellFolderGetDragDataEventArgs) SetBytesToRead(value int32)

func (args *ShellFolderGetDragDataEventArgs) ResultCode() int32
func (args *ShellFolderGetDragDataEventArgs) SetResultCode(value int32)

// ShellFolderGetDragDataEvent defines the signature of the ShellFolder GetDragData event's handler function.
type ShellFolderGetDragDataEvent func(sender *ShellFolder, args *ShellFolderGetDragDataEventArgs)

func (obj *ShellFolder) GetOnGetDragDataHandler() ShellFolderGetDragDataEvent
func (obj *ShellFolder) SetOnGetDragDataHandler(handlerFunc ShellFolderGetDragDataEvent)

Remarks

This event is fired when a drag operation has started within the virtual folder and the struct needs to collect data for the drag operation. The event fires twice for each format supported for the ongoing operation. Initially, it fires to obtain the size of the drag data it needs to collect (see below for details). After the struct obtains the size information, the event fires once more to collect the data for a given format associated with the ongoing drag-and-drop operation.

The TaskId parameter is set to the same value as in the Drag event fired when the drag-and-drop operation started.

The Format contains the clipboard format Id of the format in which the data is required. This will be one of the formats reported as supported by the Drag event.

The Buffer parameter acts as the destination buffer for the data being requested. If the event fires and the number of bytes specified by the BytesToRead parameter is sufficient to store the drag data, the event handler should copy the data into the Buffer. In this case, the BytesToRead parameter must be set to the actual number of bytes copied into the Buffer, and the ResultCode parameter must be set to 0.

The BytesToRead parameter indicates the size of the data that is being requested. When the event first fires to request the size of the drag data, its value will be set to 0. If the event fires and the number of bytes specified in BytesToRead is less than the size of the drag data that will be copied into the destination Buffer, this parameter should be set to the size of the drag data and the ResultCode parameter must be set to CBFSSHELL_ERR_INSUFFICIENT_BUFFER.

The ResultCode parameter indicates the outcome of the event. By default, its value will always be 0. If the event cannot be handled successfully, its value can be set to an appropriate value to report an error. For example, if no item was found, set ResultCode to CBFSSHELL_ERR_FILE_NOT_FOUND.

Please refer to the Error Codes section for the set of possible values.

If an unhandled exception occurs within the event handler, the struct will catch it and report an internal error.

GetInfoBar Event (ShellFolder Component)

This event is fired to show an information bar for a folder that is about to be displayed.

Syntax

// ShellFolderGetInfoBarEventArgs carries the ShellFolder GetInfoBar event's parameters.
type ShellFolderGetInfoBarEventArgs struct {...}

func (args *ShellFolderGetInfoBarEventArgs) FolderId() string
func (args *ShellFolderGetInfoBarEventArgs) InfoBarId() string
func (args *ShellFolderGetInfoBarEventArgs) SetInfoBarId(value string)

func (args *ShellFolderGetInfoBarEventArgs) Text() string
func (args *ShellFolderGetInfoBarEventArgs) SetText(value string)

// ShellFolderGetInfoBarEvent defines the signature of the ShellFolder GetInfoBar event's handler function.
type ShellFolderGetInfoBarEvent func(sender *ShellFolder, args *ShellFolderGetInfoBarEventArgs)

func (obj *ShellFolder) GetOnGetInfoBarHandler() ShellFolderGetInfoBarEvent
func (obj *ShellFolder) SetOnGetInfoBarHandler(handlerFunc ShellFolderGetInfoBarEvent)

Remarks

This event is fired by the struct when the Windows Shell is going to display a folder. It provides an opportunity to immediately display an information bar for the folder. Alternatively, an information bar can be displayed at another time by using the ShowInfoBar method.

The FolderId parameter specifies the item Id of the folder for which the information bar will be displayed. If the folder specified by FolderId is not visible, the information bar will not be shown.

The InfoBarId parameter specifies the GUID of the information bar. This acts as an identifier that can be used to hide the bar later. If set to an empty value, the information bar will not be displayed. The GUID must be specified in Registry Format. For instance: {1FAD0EF2-9A03-4B87-B4BC-645B7035ED90}.

The Text parameter is the text content to be displayed in the information bar. If set to an empty value, the information bar will not be displayed.

GetInfoTip Event (ShellFolder Component)

This event is fired when the infotip of an item is about to be displayed.

Syntax

// ShellFolderGetInfoTipEventArgs carries the ShellFolder GetInfoTip event's parameters.
type ShellFolderGetInfoTipEventArgs struct {...}

func (args *ShellFolderGetInfoTipEventArgs) ItemId() string
func (args *ShellFolderGetInfoTipEventArgs) InfoTip() string
func (args *ShellFolderGetInfoTipEventArgs) SetInfoTip(value string)

// ShellFolderGetInfoTipEvent defines the signature of the ShellFolder GetInfoTip event's handler function.
type ShellFolderGetInfoTipEvent func(sender *ShellFolder, args *ShellFolderGetInfoTipEventArgs)

func (obj *ShellFolder) GetOnGetInfoTipHandler() ShellFolderGetInfoTipEvent
func (obj *ShellFolder) SetOnGetInfoTipHandler(handlerFunc ShellFolderGetInfoTipEvent)

Remarks

This event is fired by the struct when the Windows Shell is going to display an infotip for an item. The event provides an opportunity to dynamically add an infotip by modifying the event's parameters. Alternatively, an infotip can be set statically via the AddProperty method.

The ItemId parameter contains the item Id of the item for which the infotip will be displayed.

The InfoTip parameter specifies the text content of the infotip.

GetItemData Event (ShellFolder Component)

This event is fired when the Windows Shell is reading the contents of an item.

Syntax

// ShellFolderGetItemDataEventArgs carries the ShellFolder GetItemData event's parameters.
type ShellFolderGetItemDataEventArgs struct {...}

func (args *ShellFolderGetItemDataEventArgs) ItemId() string
func (args *ShellFolderGetItemDataEventArgs) Start() int64
func (args *ShellFolderGetItemDataEventArgs) Length() int32
func (args *ShellFolderGetItemDataEventArgs) SetLength(value int32)

func (args *ShellFolderGetItemDataEventArgs) Buffer() []byte
func (args *ShellFolderGetItemDataEventArgs) ResultCode() int32
func (args *ShellFolderGetItemDataEventArgs) SetResultCode(value int32)

// ShellFolderGetItemDataEvent defines the signature of the ShellFolder GetItemData event's handler function.
type ShellFolderGetItemDataEvent func(sender *ShellFolder, args *ShellFolderGetItemDataEventArgs)

func (obj *ShellFolder) GetOnGetItemDataHandler() ShellFolderGetItemDataEvent
func (obj *ShellFolder) SetOnGetItemDataHandler(handlerFunc ShellFolderGetItemDataEvent)

Remarks

This event is fired by the struct when the Windows Shell needs to read a block of data from an item. An event handler for this event is responsible for populating the contents of the items in the virtual folder by providing this data as it is requested.

The event does not fire for physical items (i.e., the ones backed by a file on the existing filesysten) and for items, whose size was previously set to -1.

The ItemId parameter contains the Id of the item for which data is requested.

The Start parameter contains the number of bytes of data for the current item that have already been read by the system. It specifies the starting position for copying data into the Buffer parameter.

The Length parameter specifies the maximum number of bytes the system will read from the data provided. Its value should be set to the actual number of bytes that will be written to the Buffer parameter.

The Buffer parameter acts as the destination buffer for the data being requested. An event handler should copy up to Length bytes from the item's data source into Buffer, starting at the position specified by the Start parameter.

The ResultCode parameter indicates the outcome of the event. By default, its value will always be 0. If the event cannot be handled successfully, its value can be set to an appropriate value to report an error. For example, if no item was found, set ResultCode to CBFSSHELL_ERR_FILE_NOT_FOUND.

Please refer to the Error Codes section for the set of possible values.

If an unhandled exception occurs within the event handler, the struct will catch it and report an internal error.

The event handler may set ResultCode to CBFSSHELL_ERR_STREAM_EOF if no data could be read at all. If at least one byte was read and has to be passed to the Windows Shell, set ResultCode to 0 instead.

GetItemId Event (ShellFolder Component)

This event is fired when the system needs the identifier of an item.

Syntax

// ShellFolderGetItemIdEventArgs carries the ShellFolder GetItemId event's parameters.
type ShellFolderGetItemIdEventArgs struct {...}

func (args *ShellFolderGetItemIdEventArgs) ParentId() string
func (args *ShellFolderGetItemIdEventArgs) DisplayName() string
func (args *ShellFolderGetItemIdEventArgs) ItemId() string
func (args *ShellFolderGetItemIdEventArgs) SetItemId(value string)

func (args *ShellFolderGetItemIdEventArgs) ResultCode() int32
func (args *ShellFolderGetItemIdEventArgs) SetResultCode(value int32)

// ShellFolderGetItemIdEvent defines the signature of the ShellFolder GetItemId event's handler function.
type ShellFolderGetItemIdEvent func(sender *ShellFolder, args *ShellFolderGetItemIdEventArgs)

func (obj *ShellFolder) GetOnGetItemIdHandler() ShellFolderGetItemIdEvent
func (obj *ShellFolder) SetOnGetItemIdHandler(handlerFunc ShellFolderGetItemIdEvent)

Remarks

This event is fired by the struct when it needs to find the identifier of an item defined by its display name.

The ParentId parameter contains the Id of the parent of the item that needs to be identified.

The DisplayName parameter contains the display name of the item that needs to be identified.

The ItemId parameter specifies the Id of the item that needs to be identified. This value should be set to the Id of the item with a display name equal to DisplayName. If the item cannot be found, ItemId should be set to an empty value. If an item Id is specified by the event handler, the struct will fire the GetItemInfo event to retrieve more information about the item.

The ResultCode parameter indicates the outcome of the event. By default, its value will always be 0. If the event cannot be handled successfully, its value can be set to an appropriate value to report an error. For example, if no item was found, set ResultCode to CBFSSHELL_ERR_FILE_NOT_FOUND.

Please refer to the Error Codes section for the set of possible values.

If an unhandled exception occurs within the event handler, the struct will catch it and report an internal error.

If an item with the given display name has not been found (which may be the case when a new item is attempted to be created), the handler should set ResultCode to CBFSSHELL_ERR_FILE_NOT_FOUND.

GetItemInfo Event (ShellFolder Component)

This event is fired when information about an item needs to be retrieved.

Syntax

// ShellFolderGetItemInfoEventArgs carries the ShellFolder GetItemInfo event's parameters.
type ShellFolderGetItemInfoEventArgs struct {...}

func (args *ShellFolderGetItemInfoEventArgs) ItemId() string
func (args *ShellFolderGetItemInfoEventArgs) Attributes() int64
func (args *ShellFolderGetItemInfoEventArgs) SetAttributes(value int64)

func (args *ShellFolderGetItemInfoEventArgs) Size() int64
func (args *ShellFolderGetItemInfoEventArgs) SetSize(value int64)

func (args *ShellFolderGetItemInfoEventArgs) DisplayName() string
func (args *ShellFolderGetItemInfoEventArgs) SetDisplayName(value string)

func (args *ShellFolderGetItemInfoEventArgs) FileSystemPath() string
func (args *ShellFolderGetItemInfoEventArgs) SetFileSystemPath(value string)

func (args *ShellFolderGetItemInfoEventArgs) IconPath() string
func (args *ShellFolderGetItemInfoEventArgs) SetIconPath(value string)

func (args *ShellFolderGetItemInfoEventArgs) IconIndex() int32
func (args *ShellFolderGetItemInfoEventArgs) SetIconIndex(value int32)

func (args *ShellFolderGetItemInfoEventArgs) ResultCode() int32
func (args *ShellFolderGetItemInfoEventArgs) SetResultCode(value int32)

// ShellFolderGetItemInfoEvent defines the signature of the ShellFolder GetItemInfo event's handler function.
type ShellFolderGetItemInfoEvent func(sender *ShellFolder, args *ShellFolderGetItemInfoEventArgs)

func (obj *ShellFolder) GetOnGetItemInfoHandler() ShellFolderGetItemInfoEvent
func (obj *ShellFolder) SetOnGetItemInfoHandler(handlerFunc ShellFolderGetItemInfoEvent)

Remarks

This event is fired when the struct needs to retrieve information about an item. The event will also fire when the RefreshItem method is called and the struct needs to update cached information about an item.

The ItemId parameter contains the Id of the item for which information will be retrieved.

The Attributes parameter is used to specify the attributes of the item. When there exists some cached information that needs to be updated, the value of this parameter is non-zero. If this is the case, changing of the SFGAO_FOLDER flag has no effect (this flag will be set by struct to the existing value). Available attributes are:

SFGAO_CANCOPY0x00000001The specified items can be copied.

SFGAO_CANMOVE0x00000002The specified items can be moved.

SFGAO_CANLINK0x00000004Shortcuts can be created for the specified items.

If a namespace extension returns this attribute, a Create Shortcut entry with a default handler is added to the shortcut menu that is displayed during drag-and-drop operations. The extension can also implement its own handler for the link verb in place of the default. If the extension does so, it is responsible for creating the shortcut. A Create Shortcut item is also added to Windows File Explorer's File menu and to normal shortcut menus.

SFGAO_STORAGE0x00000008The specified items can be bound to an IStorage object.

Should not be changed if item content is used.

SFGAO_CANRENAME0x00000010The specified items can be renamed.

SFGAO_CANDELETE0x00000020The specified items can be deleted.

SFGAO_HASPROPSHEET0x00000040The specified items have property sheets.

SFGAO_DROPTARGET0x00000100The specified items are drop targets.

SFGAO_PLACEHOLDER0x00000800The specified items are not fully present and recalled on open or access.

SFGAO_SYSTEM0x00001000The specified items are system items.

SFGAO_ENCRYPTED0x00002000The specified items are encrypted and might require special presentation.

SFGAO_ISSLOW0x00004000Accessing the item (through IStream or other storage interfaces) is expected to be a slow operation.

Applications should avoid accessing items flagged with SFGAO_ISSLOW.

SFGAO_GHOSTED0x00008000The specified items are shown as dimmed and unavailable to the user.

SFGAO_LINK0x00010000The specified items are shortcuts.

SFGAO_SHARE0x00020000The specified objects are shared.

SFGAO_READONLY0x00040000The specified items are read-only.

In the case of folders, this means that new items cannot be created in those folders. This should not be confused with the behavior specified by the file Read-Only attribute.

SFGAO_HIDDEN0x00080000The item is hidden and should not be displayed unless the Show hidden files and folders option is enabled in Folder Settings.

ShellItem property: IsHidden.

SFGAO_NONENUMERATED0x00100000The items are non-enumerated items and should be hidden.

Should not be changed.

SFGAO_NEWCONTENT0x00200000The items contain new content, as defined by the particular application.

SFGAO_STREAM0x00400000Indicates that the item has a stream associated with it.

Should not be changed if item content is used. Default for items: true.

SFGAO_STORAGEANCESTOR0x00800000Children of this item are accessible through IStream or IStorage. Those children are flagged with SFGAO_STORAGE or SFGAO_STREAM.

Should not be changed if item content is used.

SFGAO_VALIDATE0x01000000When specified as input, SFGAO_VALIDATE instructs the folder to validate that the items contained in a folder or Windows Shell item array exist.

Should not be changed.

SFGAO_REMOVABLE0x02000000The specified items are on removable media or are themselves removable devices.

SFGAO_COMPRESSED0x04000000The specified items are compressed.

SFGAO_BROWSABLE0x08000000The specified items can be hosted inside a web browser or Explorer frame.

To be used with non-folder items.

SFGAO_FILESYSANCESTOR0x10000000The specified folders are either file system folders or contain at least one descendant (child, grandchild, or later) that is a file system (SFGAO_FILESYSTEM) folder.

This attribute is added automatically to folders that represent filesystem objects. If the root folder is expected to contain filesystem items, add this flag to the Attributes property of the ShellFolder struct.

SFGAO_FOLDER0x20000000The specified items are folders.

Should not be changed. In the ShellFolder struct, this flag is added or removed automatically depending on the value of the IsFolder parameter of the ListItem method.

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

The parsed names of the items can be assumed to be valid Win32 file system paths. These paths can be either UNC or drive-letter based.

This attribute is added automatically to folders and items that represent filesystem objects.

SFGAO_HASSUBFOLDER0x80000000The specified folders have subfolders.

The SFGAO_HASSUBFOLDER attribute is only advisory and might be returned by Windows Shell folder implementations even if they do not contain subfolders. Note, however, that the converse - failing to return SFGAO_HASSUBFOLDER - definitively states that the folder objects do not have subfolders. Returning SFGAO_HASSUBFOLDER is recommended whenever a significant amount of time is required to determine whether any subfolders exist. For example, the Windows Shell always returns SFGAO_HASSUBFOLDER when a folder is located on a network drive.

Already handled, but may be changed if needed (when the application can determine for sure that the folder is empty).

SFGAO_DEFAULT_ROOT0xA0C00108Default value for the namespace root folder.

This attribute is a combination of SFGAO_FOLDER, SFGAO_HASSUBFOLDER, SFGAO_STREAM, SFGAO_STORAGEANCESTOR, SFGAO_DROPTARGET, SFGAO_STORAGE, and is used to initialize the value of the Attributes property of ShellFolder.

The default values for Attributes of virtual items are listed below. This is only applicable when FileSystemPath is empty.

The default attributes for virtual folders are as follows.

The default values for Attributes of physical items are listed below. This is only applicable when FileSystemPath specifies the path to the file or folder on disk.

The default attributes for physical folders are as follows.

The Size parameter can be used to specify the size of the item data that one may copy. Set the value to -1 to tell the struct that an item has no data available for reading. When this value is set, GetItemData does not fire. The parameter is ignored for items with FileSystemPath set as well as for folders.

The DisplayName parameter specifies the human-readable name of the item. This may be the name of a file or directory represented by this item, or some other meaningful text for a user.

The FileSystemPath specifies the path to the file on disk if the item is a physical file and represents a file or directory on a filesystem. If the item is virtual and has no representation on a filesystem, pass an empty string for this parameter. See the Physical and Virtual Windows Shell Items topic in the introduction for additional information.

The IconPath parameter specifies the path to the DLL or EXE file that contains the icon for the item.

The IconIndex parameter determines which icon is displayed for the item. Its value may be either the index or Id of the specific icon within the resources of the DLL or EXE file in IconPath. Note that an index must be a positive number, while an Id value must be a negative number.

The ResultCode parameter indicates the outcome of the event. By default, its value will always be 0. If the event cannot be handled successfully, its value can be set to an appropriate value to report an error. For example, if no item was found, set ResultCode to CBFSSHELL_ERR_FILE_NOT_FOUND.

Please refer to the Error Codes section for the set of possible values.

If an unhandled exception occurs within the event handler, the struct will catch it and report an internal error.

GetNameLimits Event (ShellFolder Component)

This event is fired to collect information about naming constraints for items in a folder.

Syntax

// ShellFolderGetNameLimitsEventArgs carries the ShellFolder GetNameLimits event's parameters.
type ShellFolderGetNameLimitsEventArgs struct {...}

func (args *ShellFolderGetNameLimitsEventArgs) FolderId() string
func (args *ShellFolderGetNameLimitsEventArgs) MaxLength() int32
func (args *ShellFolderGetNameLimitsEventArgs) SetMaxLength(value int32)

func (args *ShellFolderGetNameLimitsEventArgs) AllowedChars() string
func (args *ShellFolderGetNameLimitsEventArgs) SetAllowedChars(value string)

func (args *ShellFolderGetNameLimitsEventArgs) DisallowedChars() string
func (args *ShellFolderGetNameLimitsEventArgs) SetDisallowedChars(value string)

// ShellFolderGetNameLimitsEvent defines the signature of the ShellFolder GetNameLimits event's handler function.
type ShellFolderGetNameLimitsEvent func(sender *ShellFolder, args *ShellFolderGetNameLimitsEventArgs)

func (obj *ShellFolder) GetOnGetNameLimitsHandler() ShellFolderGetNameLimitsEvent
func (obj *ShellFolder) SetOnGetNameLimitsHandler(handlerFunc ShellFolderGetNameLimitsEvent)

Remarks

This event fires to retrieve optional information about constraints that should be applied when an item is created or renamed. If the event is not handled or the corresponding parameter is not set, default values apply.

The FolderId parameter contains the item Id of the folder, items of which will be created or rename. An empty value for FolderId indicates the root folder of the Windows Shell Namespace branch.

The MaxLength parameter specifies the maximum character length of the item's display name. Its value is set to 0 by default.

The AllowedChars parameter defines the set of characters allowed in the item's display name. Its value is case-sensitive. An empty value indicates that any character is allowed except for the ones specified in the DisallowedChars parameter.

The DisallowedChars parameter defines the set of characters that are not allowed in the item's display name. Its value case-sensitive and is only considered when AllowedChars is set to an empty value. When the event fires, its value is set to "/:*?"<>|" by default.

GetProperties Event (ShellFolder Component)

This event is fired when the properties of an item need to be listed.

Syntax

// ShellFolderGetPropertiesEventArgs carries the ShellFolder GetProperties event's parameters.
type ShellFolderGetPropertiesEventArgs struct {...}

func (args *ShellFolderGetPropertiesEventArgs) TaskId() int32
func (args *ShellFolderGetPropertiesEventArgs) ItemId() string
func (args *ShellFolderGetPropertiesEventArgs) ResultCode() int32
func (args *ShellFolderGetPropertiesEventArgs) SetResultCode(value int32)

// ShellFolderGetPropertiesEvent defines the signature of the ShellFolder GetProperties event's handler function.
type ShellFolderGetPropertiesEvent func(sender *ShellFolder, args *ShellFolderGetPropertiesEventArgs)

func (obj *ShellFolder) GetOnGetPropertiesHandler() ShellFolderGetPropertiesEvent
func (obj *ShellFolder) SetOnGetPropertiesHandler(handlerFunc ShellFolderGetPropertiesEvent)

Remarks

This event is fired by the struct when it needs to retrieve properties of an item. The event is fired for each item listed during the ListItems event, right after all items have been reported. An event handler for this event determines the properties of each item as they are enumerated. To assign these properties, the AddProperty method should be called within the handler for each property that will be added to the item.

The ItemId parameter contains the item Id of the item for which properties are being retrieved.

The TaskId parameter identifies the current operation and is required when calling the AddProperty method.

The ResultCode parameter indicates the outcome of the event. By default, its value will always be 0. If the event cannot be handled successfully, its value can be set to an appropriate value to report an error. For example, if no item was found, set ResultCode to CBFSSHELL_ERR_FILE_NOT_FOUND.

Please refer to the Error Codes section for the set of possible values.

If an unhandled exception occurs within the event handler, the struct will catch it and report an internal error.

Virtual Item Data

When adding the properties of a virtual item that contains data, it is important to pass its data size to the struct. This ensures that the component can properly fire the GetItemData event when the item is copied or accessed. This is done by adding a property using AddProperty with the following parameters:

  • Set the FormatId parameter to b725f130-47ef-101a-a5f1-02608c9eebac.
  • Set the PropertyId parameter to 12.
  • Set the PropType parameter to PROP_TYPE_LONG.

An sample call to add this propety would be: MyShellFolder.AddProperty(TaskId, "b725f130-47ef-101a-a5f1-02608c9eebac", 12, 2, ItemDataLength, DateTime.MinValue, null);

InvokeMenu Event (ShellFolder Component)

This event is fired when an item of the context menu is invoked.

Syntax

// ShellFolderInvokeMenuEventArgs carries the ShellFolder InvokeMenu event's parameters.
type ShellFolderInvokeMenuEventArgs struct {...}

func (args *ShellFolderInvokeMenuEventArgs) Verb() string
func (args *ShellFolderInvokeMenuEventArgs) FolderId() string
// ShellFolderInvokeMenuEvent defines the signature of the ShellFolder InvokeMenu event's handler function.
type ShellFolderInvokeMenuEvent func(sender *ShellFolder, args *ShellFolderInvokeMenuEventArgs)

func (obj *ShellFolder) GetOnInvokeMenuHandler() ShellFolderInvokeMenuEvent
func (obj *ShellFolder) SetOnInvokeMenuHandler(handlerFunc ShellFolderInvokeMenuEvent)

Remarks

This event is fired when a context menu item is invoked. To obtain the list of Windows Shell items for which the context menu was invoked, use the SelectedItems property.

The Verb parameter contains the unique text identifier of the menu item that was invoked.

The FolderId parameter contains the item Id of the folder where the context menu was invoked.

Menu Items from a "New" Submenu

The Windows Shell appends a "New" submenu to the context menu when a menu item is added with the MergeMenuTop event with its ShowNewMenu parameter set to true. This submenu comes with a set of predefined operations, each with their own respective verbs. An event handler for this method may use these verbs to handle the operations that correspond to the items within this submenu. The possible values for these verbs include:

  • The newfolder verb for creating a new folder.
  • The newlink verb for creating a new shortcut.
  • A file extension verb, such as .txt, for creating a new file of its respective type.

UI Considerations

Event handlers are called in the context of threads that run in the MTA (multithreaded apartment) state. This state is not suitable for showing UI elements. Thus, event handlers should create an STA thread and use it to display a needed window. For example:

var thread = new Thread(() => { ... } // "..." is the code that an event handler executes in a helper thread thread.SetApartmentState(ApartmentState.STA); thread.IsBackground = true; thread.Start(); thread.Join(); // optional, if your code should work synchronously

ListItems Event (ShellFolder Component)

This event is fired when the contents of a folder are listed.

Syntax

// ShellFolderListItemsEventArgs carries the ShellFolder ListItems event's parameters.
type ShellFolderListItemsEventArgs struct {...}

func (args *ShellFolderListItemsEventArgs) TaskId() int32
func (args *ShellFolderListItemsEventArgs) ParentId() string
func (args *ShellFolderListItemsEventArgs) Flags() int32
func (args *ShellFolderListItemsEventArgs) ResultCode() int32
func (args *ShellFolderListItemsEventArgs) SetResultCode(value int32)

// ShellFolderListItemsEvent defines the signature of the ShellFolder ListItems event's handler function.
type ShellFolderListItemsEvent func(sender *ShellFolder, args *ShellFolderListItemsEventArgs)

func (obj *ShellFolder) GetOnListItemsHandler() ShellFolderListItemsEvent
func (obj *ShellFolder) SetOnListItemsHandler(handlerFunc ShellFolderListItemsEvent)

Remarks

This event is fired when the system requests information about a folder's contents. An event handler for this event determines the items and subfolders that get included in the folder. To include them, the ListItem method should be called within the handler for each individual item and subfolder that will be in the folder.

The GetProperties event will fire for each of the listed items. Following this, the GetColumns event and then the GetNameLimits event will sequentially fire for each of the listed folders.

The TaskId parameter identifies the current operation and is required when calling the ListItem method.

The ParentId parameter is the item Id of the folder being listed. An empty value indicates that the root folder is being listed.

The Flags parameter controls the types of items included in the folder. Its value may be one or more of the following flags OR'd together:

SHCONTF_FOLDERS0x00000020Include items that are folders in the enumeration.

Do not include folders when the flag is not set.

SHCONTF_NONFOLDERS0x00000040Include items that are not folders in the enumeration.

Do not include non-folder items when the flag is not set.

SHCONTF_INCLUDEHIDDEN0x00000080Include items that are hidden but not system in the enumeration.

Do not include hidden system items when the flag is set.

SHCONTF_INCLUDESUPERHIDDEN0x00010000Include items that are both system and hidden in the enumeration.

Do not include just hidden (non-system) system items when the flag is set.

The ResultCode parameter indicates the outcome of the event. By default, its value will always be 0. If the event cannot be handled successfully, its value can be set to an appropriate value to report an error. For example, if no item was found, set ResultCode to CBFSSHELL_ERR_FILE_NOT_FOUND.

Please refer to the Error Codes section for the set of possible values.

If an unhandled exception occurs within the event handler, the struct will catch it and report an internal error.

MergeMenu Event (ShellFolder Component)

This event is fired when a context menu is shown for one or more items.

Syntax

// ShellFolderMergeMenuEventArgs carries the ShellFolder MergeMenu event's parameters.
type ShellFolderMergeMenuEventArgs struct {...}

func (args *ShellFolderMergeMenuEventArgs) TaskId() int32
func (args *ShellFolderMergeMenuEventArgs) FolderId() string
func (args *ShellFolderMergeMenuEventArgs) ExistingVerbs() string
func (args *ShellFolderMergeMenuEventArgs) Flags() int32
func (args *ShellFolderMergeMenuEventArgs) ResultCode() int32
func (args *ShellFolderMergeMenuEventArgs) SetResultCode(value int32)

// ShellFolderMergeMenuEvent defines the signature of the ShellFolder MergeMenu event's handler function.
type ShellFolderMergeMenuEvent func(sender *ShellFolder, args *ShellFolderMergeMenuEventArgs)

func (obj *ShellFolder) GetOnMergeMenuHandler() ShellFolderMergeMenuEvent
func (obj *ShellFolder) SetOnMergeMenuHandler(handlerFunc ShellFolderMergeMenuEvent)

Remarks

This event is fired by the struct when the Windows Shell is about to show a context menu for one or more Windows Shell items. To obtain the list of Windows Shell items for which the context menu is about to be displayed, use the SelectedItems property.

To handle the event properly, an event handler must call the AddMenuItem method in a loop, with each additional menu command reported using a call to this method. The event handler should return when it finishes listing all menu items. An application may add own menu items and remove the existing ones on each step outlined above; however, each item needs to be added on just one step to prevent duplication.

The TaskId parameter identifies the current operation and is required when calling the AddMenuItem method.

The FolderId parameter contains the item Id of the folder where the context menu was invoked.

The ExistingVerbs parameter contains a list of verbs for menu items already in the menu, separated with the LF character (numeric code 10). This list may include items from the Windows Shell, other Windows Shell extensions, or those added previously by the event handler. The event handler can use the RemoveMenuItem method to remove any of these existing menu items.

The Flags parameter contains various flags that determine the content and behavior of the menu. The list of valid values for this parameter can be found in the MSDN page for the IContextMenu::QueryContextMenu method under the list of CMF_* flags.

The ExistingVerbs parameter contains a list of verbs for menu items already in the menu, separated with the LF character (numeric code 10). This list may include items from the Windows Shell, other Windows Shell extensions, or those added previously by the event handler. The event handler can use the RemoveMenuItem method to remove any of these existing menu items.

The ResultCode parameter indicates the outcome of the event. By default, its value will always be 0. If the event cannot be handled successfully, its value can be set to an appropriate value to report an error. For example, if no item was found, set ResultCode to CBFSSHELL_ERR_FILE_NOT_FOUND.

Please refer to the Error Codes section for the set of possible values.

If an unhandled exception occurs within the event handler, the struct will catch it and report an internal error.

Menu Item Placement

The Windows Shell makes requests to merge a menu in three distinct phases. Initially, menu items are merged in an order defined by the system. In the second phase, additional items are placed at the bottom of the menu. The final phase adds items to the top of the menu. For each phase, the component triggers a corresponding event: MergeMenu for the initial ordering, MergeMenuBottom for adding items to the bottom, and MergeMenuTop for adding items to the top.

Some applications or Windows Shell extensions may need to add their menu items after the initial phase. Due to this, the last two events may be more appropriate for adding new items or removing those recently added by other applications..

MergeMenuBottom Event (ShellFolder Component)

This event is fired when a context menu is shown for one or more items.

Syntax

// ShellFolderMergeMenuBottomEventArgs carries the ShellFolder MergeMenuBottom event's parameters.
type ShellFolderMergeMenuBottomEventArgs struct {...}

func (args *ShellFolderMergeMenuBottomEventArgs) TaskId() int32
func (args *ShellFolderMergeMenuBottomEventArgs) FolderId() string
func (args *ShellFolderMergeMenuBottomEventArgs) ExistingVerbs() string
func (args *ShellFolderMergeMenuBottomEventArgs) Flags() int32
func (args *ShellFolderMergeMenuBottomEventArgs) ResultCode() int32
func (args *ShellFolderMergeMenuBottomEventArgs) SetResultCode(value int32)

// ShellFolderMergeMenuBottomEvent defines the signature of the ShellFolder MergeMenuBottom event's handler function.
type ShellFolderMergeMenuBottomEvent func(sender *ShellFolder, args *ShellFolderMergeMenuBottomEventArgs)

func (obj *ShellFolder) GetOnMergeMenuBottomHandler() ShellFolderMergeMenuBottomEvent
func (obj *ShellFolder) SetOnMergeMenuBottomHandler(handlerFunc ShellFolderMergeMenuBottomEvent)

Remarks

This event is fired by the struct when the Windows Shell is about to show a context menu for one or more Windows Shell items. Items added by an event handler are merged at the bottom of the existing menu. To obtain the list of Windows Shell items for which the context menu is about to be displayed, use the SelectedItems property.

To handle the event properly, an event handler must call the AddMenuItem method in a loop, with each additional menu command reported using a call to this method. The event handler should return when it finishes listing all menu items. An application may add own menu items and remove the existing ones on each step outlined above; however, each item needs to be added on just one step to prevent duplication.

The TaskId parameter identifies the current operation and is required when calling the AddMenuItem method.

The FolderId parameter contains the item Id of the folder where the context menu was invoked.

The ExistingVerbs parameter contains a list of verbs for menu items already in the menu, separated with the LF character (numeric code 10). This list may include items from the Windows Shell, other Windows Shell extensions, or those added previously by the event handler. The event handler can use the RemoveMenuItem method to remove any of these existing menu items.

The Flags parameter contains various flags that determine the content and behavior of the menu. The list of valid values for this parameter can be found in the MSDN page for the IContextMenu::QueryContextMenu method under the list of "CFM_* flags".

The ExistingVerbs parameter contains a list of verbs for menu items already in the menu, separated with the LF character (numeric code 10). This list may include items from the Windows Shell, other Windows Shell extensions, or those added previously by the event handler. The event handler can use the RemoveMenuItem method to remove any of these existing menu items.

The ResultCode parameter indicates the outcome of the event. By default, its value will always be 0. If the event cannot be handled successfully, its value can be set to an appropriate value to report an error. For example, if no item was found, set ResultCode to CBFSSHELL_ERR_FILE_NOT_FOUND.

Please refer to the Error Codes section for the set of possible values.

If an unhandled exception occurs within the event handler, the struct will catch it and report an internal error.

MergeMenuTop Event (ShellFolder Component)

This event is fired when a context menu is shown for one or more items.

Syntax

// ShellFolderMergeMenuTopEventArgs carries the ShellFolder MergeMenuTop event's parameters.
type ShellFolderMergeMenuTopEventArgs struct {...}

func (args *ShellFolderMergeMenuTopEventArgs) TaskId() int32
func (args *ShellFolderMergeMenuTopEventArgs) FolderId() string
func (args *ShellFolderMergeMenuTopEventArgs) ExistingVerbs() string
func (args *ShellFolderMergeMenuTopEventArgs) Flags() int32
func (args *ShellFolderMergeMenuTopEventArgs) ShowNewMenu() bool
func (args *ShellFolderMergeMenuTopEventArgs) SetShowNewMenu(value bool)

func (args *ShellFolderMergeMenuTopEventArgs) ResultCode() int32
func (args *ShellFolderMergeMenuTopEventArgs) SetResultCode(value int32)

// ShellFolderMergeMenuTopEvent defines the signature of the ShellFolder MergeMenuTop event's handler function.
type ShellFolderMergeMenuTopEvent func(sender *ShellFolder, args *ShellFolderMergeMenuTopEventArgs)

func (obj *ShellFolder) GetOnMergeMenuTopHandler() ShellFolderMergeMenuTopEvent
func (obj *ShellFolder) SetOnMergeMenuTopHandler(handlerFunc ShellFolderMergeMenuTopEvent)

Remarks

This event is fired by the struct when the Windows Shell is about to show a context menu for one or more Windows Shell items. Items added by an event handler for this method are merged at the top of the existing menu. To obtain the list of Windows Shell items for which the context menu is about to be displayed, use the SelectedItems property.

To handle the event properly, an event handler must call the AddMenuItem method in a loop, with each additional menu command reported using a call to this method. The event handler should return when it finishes listing all menu items. An application may add own menu items and remove the existing ones on each step outlined above; however, each item needs to be added on just one step to prevent duplication.

The TaskId parameter identifies the current operation and is required when calling the AddMenuItem method.

The FolderId parameter contains the item Id of the folder where the context menu was invoked.

The ExistingVerbs parameter contains a list of verbs for menu items already in the menu, separated with the LF character (numeric code 10). This list may include items from the Windows Shell, other Windows Shell extensions, or those added previously by the event handler. The event handler can use the RemoveMenuItem method to remove any of these existing menu items.

The Flags parameter contains various flags that determine the content and behavior of the menu. The list of valid values for this parameter can be found in the MSDN page for the IContextMenu::QueryContextMenu method under the list of "CFM_* flags".

The ShowNewMenu parameter determines if the "New" submenu should be included in the context menu. This submenu is only automatically included by the Windows Shell inside the context menu for a physical folder. As such, its default value is true for physical items and false for virtual items.

When ShowNewMenu is set by the event handler to true for a virtual folder, the struct inserts the New submenu into the context menu. This is done regardless of whether the folder has the SFGAO_READONLY flag in its attributes. The event handler may need to check the attribute and take the flag into account when setting ShowNewMenu.

Note: when a user initiates a context menu for a folder in the left-side tree of File Explorer, the Shell builds a menu and invokes menu-related commands twice - one time with the actual selection, and another time as if no items were selected. If the application sets ShowNewMenu to true on each iteration, the New submenu will be visually duplicated, but clicking on the second submenu will provide no selected items (as this is how this submenu was built). The solution is to add the New menu only when the number of selected items is the one you want (either zero or non-zero, but not both). However, this decision will also affect the New submenu that appears in context menus of the right-side listview.

The ResultCode parameter indicates the outcome of the event. By default, its value will always be 0. If the event cannot be handled successfully, its value can be set to an appropriate value to report an error. For example, if no item was found, set ResultCode to CBFSSHELL_ERR_FILE_NOT_FOUND.

Please refer to the Error Codes section for the set of possible values.

If an unhandled exception occurs within the event handler, the struct will catch it and report an internal error.

MoveItem Event (ShellFolder Component)

This event is fired when an item is moved.

Syntax

// ShellFolderMoveItemEventArgs carries the ShellFolder MoveItem event's parameters.
type ShellFolderMoveItemEventArgs struct {...}

func (args *ShellFolderMoveItemEventArgs) ItemId() string
func (args *ShellFolderMoveItemEventArgs) DestId() string
func (args *ShellFolderMoveItemEventArgs) DestPath() string
func (args *ShellFolderMoveItemEventArgs) DestPIDL() []byte
func (args *ShellFolderMoveItemEventArgs) ResultCode() int32
func (args *ShellFolderMoveItemEventArgs) SetResultCode(value int32)

// ShellFolderMoveItemEvent defines the signature of the ShellFolder MoveItem event's handler function.
type ShellFolderMoveItemEvent func(sender *ShellFolder, args *ShellFolderMoveItemEventArgs)

func (obj *ShellFolder) GetOnMoveItemHandler() ShellFolderMoveItemEvent
func (obj *ShellFolder) SetOnMoveItemHandler(handlerFunc ShellFolderMoveItemEvent)

Remarks

This event is fired when the Windows Shell needs to move an item.

The ItemId parameter contains the Id of the item that will be moved.

The DestId parameter contains the Id of the new parent item after the move operation is complete. This parameter will be empty if the item is moved outside of the namespace branch managed by the Windows Shell extension, such as to "C:\" or the Desktop folder.

The DestPath parameter contains the destination file path for the moved item. This parameter is only available when DestPIDL denotes a filesystem object.

The DestPIDL parameter contains the destination for the moved item as a PIDL. It will be empty if DestId is set.

The ResultCode parameter indicates the outcome of the event. By default, its value will always be 0. If the event cannot be handled successfully, its value can be set to an appropriate value to report an error. For example, if no item was found, set ResultCode to CBFSSHELL_ERR_FILE_NOT_FOUND.

Please refer to the Error Codes section for the set of possible values.

If an unhandled exception occurs within the event handler, the struct will catch it and report an internal error.

RenameItem Event (ShellFolder Component)

This event is fired when an item is renamed.

Syntax

// ShellFolderRenameItemEventArgs carries the ShellFolder RenameItem event's parameters.
type ShellFolderRenameItemEventArgs struct {...}

func (args *ShellFolderRenameItemEventArgs) ItemId() string
func (args *ShellFolderRenameItemEventArgs) NewName() string
func (args *ShellFolderRenameItemEventArgs) ResultCode() int32
func (args *ShellFolderRenameItemEventArgs) SetResultCode(value int32)

// ShellFolderRenameItemEvent defines the signature of the ShellFolder RenameItem event's handler function.
type ShellFolderRenameItemEvent func(sender *ShellFolder, args *ShellFolderRenameItemEventArgs)

func (obj *ShellFolder) GetOnRenameItemHandler() ShellFolderRenameItemEvent
func (obj *ShellFolder) SetOnRenameItemHandler(handlerFunc ShellFolderRenameItemEvent)

Remarks

This event is fired when the Windows Shell needs to rename an item.

The ItemId contains the Id of the renamed item.

The NewName parameter contains the new name of the item.

The ResultCode parameter indicates the outcome of the event. By default, its value will always be 0. If the event cannot be handled successfully, its value can be set to an appropriate value to report an error. For example, if no item was found, set ResultCode to CBFSSHELL_ERR_FILE_NOT_FOUND.

Please refer to the Error Codes section for the set of possible values.

If an unhandled exception occurs within the event handler, the struct will catch it and report an internal error.

Config Settings (ShellFolder Component)

The struct accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the struct, access to these internal properties is provided through the Config method.

ShellFolder Config Settings

ExcludeClipboardFormats:   The comma-separated list of clipboard formats that the namespace extension wants to ignore during drag-n-drop and clipboard operations.

When this setting contains one or more clipboard formats, the data in the listed formats will be skipped and will not be sent from the proxy DLL to the .NET server and to the application. These formats will stay in the clipboard but will not be visible to the event handlers. Use this setting to skip unused formats that may slow down clipboard and drag-n-drop operations.

The list may include clipboard format names or numeric Ids, e.g. "Embed Source,2" (2 is the numeric Id of CF_BITMAP).

The default value is "Embed Source", the format used by the MS Office applications for object linking and embedding.

FireCompareItems:   Whether to fire the CompareItems event.

This setting determines if the struct will fire the CompareItems event. By default, the setting is set to false for performance reasons.

FolderClassGUID:   ID of the folder class.

A folder class GUID (also known as folder class Id) is used to register a virtual folder in the Windows Registry. When shell extensions are enabled or disabled, this GUID is used by the Shell to identify the extension.

IncludeClipboardFormats:   The comma-separated list of clipboard formats that the namespace extension is interested in when handling drag-n-drop and clipboard operations.

When this setting contains one or more clipboard formats, only the data in the listed formats will be transferred from the proxy DLL to the .NET server and to the application and become available for processing. Other formats will stay in the clipboard but will not be visible to the event handlers.

The list may include clipboard format names or numeric Ids, e.g. "Shell IDList Array,15" (15 is the numeric Id of CF_HDROP, a simple list of filenames).

IPCErrorText:   The error text that will be displayed alongside the Refresh button when the native proxy DLL in the Windows Shell cannot communicate with the server (and your process).

IPCFormat:   The fixed name of the RPC endpoint.

If the Windows Shell and the server operate in different desktop sessions, set this configuration before installing the native proxy DLL.

IsInstalled:   Specifies whether the installation was performed.

This configuration setting returns true if the struct finds the required registry entries, put there by a previous call to the Install method; otherwise, false is returned. In the latter case, an application should use the Install method again.

ProductGUID:   ID of the proxy DLL.

A product GUID (also known as project ID) is used to distinguish among various installations performed by different applications. The GUID of the Windows Shell virtual folder is derived from this ID.

RefreshButtonText:   The text that will be displayed on the Refresh button in the Windows Shell folder.

This button is displayed when the native proxy DLL in the Windows Shell cannot communicate with the server (and your process).

ServerStartArguments:   The arguments to pass with the command.

Set this configuration setting before installing the native proxy DLL.

ServerStartCommandLine:   The command line to run when the server is not available.

This command is executed using the ShellExecute function of the Windows Shell API.

Set this configuration setting before installing the native proxy DLL.

ServerStartOperation:   The operation verb.

This command is executed using the ShellExecute function of the Windows Shell API. You may pass an optional operation verb to this function.

Set this configuration setting before installing the native proxy DLL.

ServerStartShowOption:   Defines how the application windows should be shown.

This value corresponds to the nShowCmd parameter of the ShellExecute function. The default value is 1 ("show normal").

Set this configuration setting before installing the native proxy DLL.

ServerStartTimeToWait:   Optional time to wait before retrying RPC connection.

The time is specified in milliseconds. The default value is 3000 (3 seconds). Set this configuration setting before installing the native proxy DLL.

ServerStartWorkingDirectory:   The working directory.

This path specifies a working directory for the started process.

Set this configuration setting before installing the native proxy DLL.

Base Config Settings

BuildInfo:   Information about the product's build.

When queried, this setting will return a string containing information about the product's build.

LicenseInfo:   Information about the current license.

When queried, this setting will return a string containing information about the license this instance of a struct is using. It will return the following information:

  • Product: The product the license is for.
  • Product Key: The key the license was generated from.
  • License Source: Where the license was found (e.g., RuntimeLicense, License File).
  • License Type: The type of license installed (e.g., Royalty Free, Single Server).

Trappable Errors (ShellFolder Component)

The struct uses the following error codes. For convenience, all of these codes are also available as constants.

ShellFolder Errors

2    An item with given ID cannot be found. The CBFSSHELL_ERR_FILE_NOT_FOUND constant is provided for convenience and may be used in place of the numeric value.
20    Cannot load native proxy DLL. The CBFSSHELL_ERR_CANT_LOAD_PROXY constant is provided for convenience and may be used in place of the numeric value.
28    The major version of the proxy DLL doesn't match the major version of the .NET assembly. The CBFSSHELL_ERR_PROXY_VERSION_MISMATCH constant is provided for convenience and may be used in place of the numeric value.
38    End of data stream has been reached and no data could be read. The CBFSSHELL_ERR_STREAM_EOF constant is provided for convenience and may be used in place of the numeric value.
55    Proxy DLL not installed properly. The CBFSSHELL_ERR_NOT_INSTALLED constant is provided for convenience and may be used in place of the numeric value.
56    Installation of the native proxy DLL failed. The CBFSSHELL_ERR_INSTALL_FAILED constant is provided for convenience and may be used in place of the numeric value.
57    Uninstallation of the native proxy DLL failed. The CBFSSHELL_ERR_UNINSTALL_FAILED constant is provided for convenience and may be used in place of the numeric value.
58    Initialization of the native proxy DLL failed. The CBFSSHELL_ERR_INIT_FAILED constant is provided for convenience and may be used in place of the numeric value.
59    The current license and the ID in the native proxy DLL name don't match. The CBFSSHELL_ERR_PROXY_NAME_MISMATCH constant is provided for convenience and may be used in place of the numeric value.
60    Writing to the Windows registry failed. The CBFSSHELL_ERR_CANT_WRITE_TO_REGISTRY constant is provided for convenience and may be used in place of the numeric value.
61    This Menu instance has already been started. The CBFSSHELL_ERR_ALREADY_STARTED constant is provided for convenience and may be used in place of the numeric value.
62    A menu item with the same verb is already registered. The CBFSSHELL_ERR_MENU_ITEM_ALREADY_REG constant is provided for convenience and may be used in place of the numeric value.
63    No menu items have been registered. The CBFSSHELL_ERR_MENU_ITEM_NOT_REG constant is provided for convenience and may be used in place of the numeric value.
87    The passed parameter was not valid. The CBFSSHELL_ERR_INVALID_PARAMETER constant is provided for convenience and may be used in place of the numeric value.
122    The provided buffer is too small to accommodate all the data that must be placed in it. The CBFSSHELL_ERR_INSUFFICIENT_BUFFER constant is provided for convenience and may be used in place of the numeric value.