using System; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using static Vanara.PInvoke.Ole32; using static Vanara.PInvoke.PropSys; namespace Vanara.PInvoke { public static partial class Shell32 { /// public const int MAX_COLUMN_NAME_LEN = 80; /// /// /// Used by members of the IColumnManager interface to specify which set of columns are being requested, either all or only those /// currently visible. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/ne-shobjidl_core-cm_enum_flags typedef enum CM_ENUM_FLAGS { // CM_ENUM_ALL, CM_ENUM_VISIBLE } ; [PInvokeData("shobjidl_core.h", MSDNShortId = "9706ae59-d172-4518-8090-375b1a0ff4fb")] public enum CM_ENUM_FLAGS { /// Enumerate all. CM_ENUM_ALL = 0x00000001, /// Enumerate visible. CM_ENUM_VISIBLE = 0x00000002, } /// /// Indicates which values in the CM_COLUMNINFO structure should be set during calls to IColumnManager::SetColumnInfo. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/ne-shobjidl_core-cm_mask typedef enum CM_MASK { CM_MASK_WIDTH, // CM_MASK_DEFAULTWIDTH, CM_MASK_IDEALWIDTH, CM_MASK_NAME, CM_MASK_STATE } ; [PInvokeData("shobjidl_core.h", MSDNShortId = "c6ba9410-7c56-428c-9ad9-4e769c047863")] public enum CM_MASK { /// The uWidth member is specified. CM_MASK_WIDTH = 0x00000001, /// The uDefaultWidth member is specified. CM_MASK_DEFAULTWIDTH = 0x00000002, /// The uIdealWidth member is specified. CM_MASK_IDEALWIDTH = 0x00000004, /// The wszName member is specified. CM_MASK_NAME = 0x00000008, /// The dwState member is specified. CM_MASK_STATE = 0x00000010, } /// /// /// Specifies width values in pixels and includes special support for default and autosize. Used by members of the IColumnManager /// interface through the CM_COLUMNINFO structure. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/ne-shobjidl_core-cm_set_width_value typedef enum // CM_SET_WIDTH_VALUE { CM_WIDTH_USEDEFAULT, CM_WIDTH_AUTOSIZE } ; [PInvokeData("shobjidl_core.h", MSDNShortId = "c5778bcc-fc9e-499a-b5e5-31c4f2df4871")] public enum CM_SET_WIDTH_VALUE { /// Use the default width. CM_WIDTH_USEDEFAULT = -1, /// Use the auto-size width. CM_WIDTH_AUTOSIZE = -2, } /// /// Specifies column state values. Used by members of the IColumnManager interface through the CM_COLUMNINFO structure. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/ne-shobjidl_core-cm_state typedef enum CM_STATE { // CM_STATE_NONE, CM_STATE_VISIBLE, CM_STATE_FIXEDWIDTH, CM_STATE_NOSORTBYFOLDERNESS, CM_STATE_ALWAYSVISIBLE } ; [PInvokeData("shobjidl_core.h", MSDNShortId = "a614dfdc-9535-40c4-9a17-5ab032113508")] public enum CM_STATE { /// The column is not currently displayed. CM_STATE_NONE = 0x00000000, /// The column is currently displayed. CM_STATE_VISIBLE = 0x00000001, /// The column cannot be resized. CM_STATE_FIXEDWIDTH = 0x00000002, /// Do not sort folders separately. CM_STATE_NOSORTBYFOLDERNESS = 0x00000004, /// The column cannot be hidden. CM_STATE_ALWAYSVISIBLE = 0x00000008, } /// /// Used by IFolderViewSettings::GetViewMode and ISearchFolderItemFactory::SetFolderLogicalViewMode to describe the view mode. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/ne-shobjidl_core-folderlogicalviewmode typedef enum // FOLDERLOGICALVIEWMODE { FLVM_UNSPECIFIED, FLVM_FIRST, FLVM_DETAILS, FLVM_TILES, FLVM_ICONS, FLVM_LIST, FLVM_CONTENT, FLVM_LAST } ; [PInvokeData("shobjidl_core.h", MSDNShortId = "4b30a335-ed80-4774-82d4-bc93c95ee80c")] public enum FOLDERLOGICALVIEWMODE { /// The view is not specified. FLVM_UNSPECIFIED, /// The minimum valid enumeration value. Used for validation purposes only. FLVM_FIRST, /// Details view. FLVM_DETAILS, /// Tiles view. FLVM_TILES, /// Icons view. FLVM_ICONS, /// Windows 7 and later. List view. FLVM_LIST, /// Windows 7 and later. Content view. FLVM_CONTENT, /// The maximum valid enumeration value. Used for validation purposes only. FLVM_LAST, } /// Flags for . [PInvokeData("shobjidl_core.h", MSDNShortId = "72528831-ec5d-417e-94dd-7345b5fd7de6")] public enum FVTEXTTYPE { /// Set the text to display when there are no items in the view. FVST_EMPTYTEXT = 0 } /// The direction in which the items are sorted. [PInvokeData("shobjidl_core.h", MSDNShortId = "3ca4c318-6462-4e22-813c-ef7b3ef03230")] public enum SORTDIRECTION { /// /// The items are sorted in ascending order. Whether the sort is alphabetical, numerical, and so on, is determined by the data /// type of the column indicated in . /// SORT_DESCENDING = -1, /// /// The items are sorted in descending order. Whether the sort is alphabetical, numerical, and so on, is determined by the data /// type of the column indicated in . /// SORT_ASCENDING = 1 } /// /// Exposes methods that enable inspection and manipulation of columns in the Windows Explorer Details view. Each column is /// referenced by a PROPERTYKEY structure, which names a property. /// /// /// /// This interface can be accessed even when the Windows Explorer window is in a non-column view mode such as icons, thumbnails, or /// tiles. It affects those views, as well as views in which the column header control displays the set of columns to which /// IColumnManager provides access. /// /// /// The default implementation of the Windows Explorer view object, created by SHCreateShellFolderViewEx, supports this interface /// retrieved through QueryInterface. Code that runs in the Windows Explorer (such as view callbacks, context menus or drop targets) /// can access the view object using IServiceProvider::QueryService, querying for SID_SFolderView. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nn-shobjidl_core-icolumnmanager [PInvokeData("shobjidl_core.h", MSDNShortId = "d01cacd8-1867-4f44-bbc3-876bd727c0fe")] [ComImport, Guid("d8ec27bb-3f3b-4042-b10a-4acfd924d453"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IColumnManager { /// Sets the state for a specified column. /// /// Type: REFPROPERTYKEY /// A reference to a PROPERTYKEY structure that identifies the column. /// /// /// Type: const CM_COLUMNINFO* /// A pointer to a CM_COLUMNINFO structure that contains the state to set for this column. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-icolumnmanager-setcolumninfo HRESULT // SetColumnInfo( REFPROPERTYKEY propkey, const CM_COLUMNINFO *pcmci ); void SetColumnInfo(in PROPERTYKEY propkey, in CM_COLUMNINFO pcmci); /// Gets information about each column: width, visibility, display name, and state. /// /// Type: REFPROPERTYKEY /// A reference to a PROPERTYKEY structure. /// /// /// Type: CM_COLUMNINFO* /// /// A pointer to a CM_COLUMNINFO structure. On entry, set this structure's dwMask member to specify the information to /// retrieve. Also set its cbSize member. When this method returns successfully, the structure contains the requested information. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-icolumnmanager-getcolumninfo HRESULT // GetColumnInfo( REFPROPERTYKEY propkey, CM_COLUMNINFO *pcmci ); void GetColumnInfo(in PROPERTYKEY propkey, ref CM_COLUMNINFO pcmci); /// Gets the column count for either the visible columns or the complete set of columns. /// /// Type: CM_ENUM_FLAGS /// /// A value from the CM_ENUM_FLAGS enumeration that specifies whether to show only visible columns or all columns regardless of visibility. /// /// /// /// Type: UINT* /// Contains a pointer to the column count. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-icolumnmanager-getcolumncount HRESULT // GetColumnCount( CM_ENUM_FLAGS dwFlags, UINT *puCount ); uint GetColumnCount(CM_ENUM_FLAGS dwFlags); /// /// Gets an array of PROPERTYKEY structures that represent the columns that the view supports. Includes either all columns or /// only those currently visible. /// /// /// Type: CM_ENUM_FLAGS /// /// A value from the CM_ENUM_FLAGS enumeration that specifies whether to show only visible columns or all columns regardless of visibility. /// /// /// /// Type: PROPERTYKEY* /// On success, contains a pointer to an array of PROPERTYKEY structures that represent the columns. /// /// /// Type: UINT /// The length of the rgkeyOrder array. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-icolumnmanager-getcolumns HRESULT // GetColumns( CM_ENUM_FLAGS dwFlags, PROPERTYKEY *rgkeyOrder, UINT cColumns ); void GetColumns(CM_ENUM_FLAGS dwFlags, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] PROPERTYKEY[] rgkeyOrder, uint cColumns); /// Sets the collection of columns for the view to display. /// /// Type: const PROPERTYKEY* /// A pointer to an array of PROPERTYKEY structures that specify the columns to display. /// /// /// Type: UINT /// The size of the rgkeyOrder array. /// /// /// NoteIColumnManager::SetColumns clears the state of all columns, so IColumnManager::SetColumnInfo must be /// called afterward to set the state of individual columns. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-icolumnmanager-setcolumns HRESULT // SetColumns( const PROPERTYKEY *rgkeyOrder, UINT cVisible ); void SetColumns([In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] PROPERTYKEY[] rgkeyOrder, uint cVisible); } /// /// Exposes methods that retrieve information about a folder's display options, select specified items in that folder, and set the /// folder's view mode. /// [ComImport, Guid("cde725b0-ccc9-4519-917e-325d72fab4ce"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [PInvokeData("Shobjidl.h", MSDNShortId = "bb761848")] public interface IFolderView { /// Gets an address containing a value representing the folder's current view mode. /// The folder's current view mode. FOLDERVIEWMODE GetCurrentViewMode(); /// Sets the selected folder's view mode. /// One of the following values from the FOLDERVIEWMODE enumeration. void SetCurrentViewMode([In] FOLDERVIEWMODE ViewMode); /// Gets the folder object. /// Reference to the desired IID to represent the folder. /// /// When this method returns, contains the interface pointer requested in . This is typically /// IShellFolder or a related interface. This can also be an IShellItemArray with a single element. /// [return: MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 0)] object GetFolder(in Guid riid); /// Gets the identifier of a specific item in the folder view, by index. /// The index of the item in the view. /// The address of a pointer to a PIDL containing the item's identifier information. PIDL Item([In] int iItemIndex); /// /// Gets the number of items in the folder. This can be the number of all items, or a subset such as the number of selected items. /// /// Flags from the _SVGIO enumeration that limit the count to certain types of items. /// The number of items (files and folders) displayed in the folder view. int ItemCount([In] SVGIO uFlags); /// Gets the address of an enumeration object based on the collection of items in the folder view. /// _SVGIO values that limit the enumeration to certain types of items. /// Reference to the desired IID to represent the folder. /// /// When this method returns, contains the interface pointer requested in . This is typically an /// IEnumIDList, IDataObject, or IShellItemArray. If an error occurs, this value is NULL. /// [return: MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 1)] object Items([In] SVGIO uFlags, in Guid riid); /// Gets the index of an item in the folder's view which has been marked by using the SVSI_SELECTIONMARK in IFolderView::SelectItem. /// The index of the marked item. int GetSelectionMarkedItem(); /// Gets the index of the item that currently has focus in the folder's view. /// The index of the item. int GetFocusedItem(); /// Gets the position of an item in the folder's view. /// A pointer to an ITEMIDLIST interface. /// The position of the item's upper-left corner. POINT GetItemPosition([In] PIDL pidl); /// /// Gets a POINT structure containing the width (x) and height (y) dimensions, including the surrounding white space, of an item. /// /// The current sizing dimensions of the items in the folder's view. POINT GetSpacing(); /// /// Gets a pointer to a POINT structure containing the default width (x) and height (y) measurements of an item, including the /// surrounding white space. /// /// The default sizing dimensions of the items in the folder's view. POINT GetDefaultSpacing(); /// Gets the current state of the folder's Auto Arrange mode. /// Returns S_OK if the folder is in Auto Arrange mode; S_FALSE if it is not. [PreserveSig] HRESULT GetAutoArrange(); /// Selects an item in the folder's view. /// The index of the item to select in the folder's view. /// One of the _SVSIF constants that specify the type of selection to apply. void SelectItem([In] int iItem, [In] SVSIF dwFlags); /// Allows the selection and positioning of items visible in the folder's view. /// The number of items to select. /// A pointer to an array of size that contains the PIDLs of the items. /// /// A pointer to an array of structures containing the locations each corresponding element in should be positioned. /// /// One of the _SVSIF constants that specifies the type of selection to apply. void SelectAndPositionItems([In] uint cidl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] apidl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] POINT[] apt, [In] SVSIF dwFlags); } /// /// Exposes methods that retrieve information about a folder's display options, select specified items in that folder, and set the /// folder's view mode. /// /// [ComImport, Guid("1af3a467-214f-4298-908e-06b03e0b39f9"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [PInvokeData("Shobjidl.h", MSDNShortId = "bb761848")] public interface IFolderView2 : IFolderView { /// Gets an address containing a value representing the folder's current view mode. /// The folder's current view mode. new FOLDERVIEWMODE GetCurrentViewMode(); /// Sets the selected folder's view mode. /// One of the following values from the FOLDERVIEWMODE enumeration. new void SetCurrentViewMode([In] FOLDERVIEWMODE ViewMode); /// Gets the folder object. /// Reference to the desired IID to represent the folder. /// /// When this method returns, contains the interface pointer requested in . This is typically /// IShellFolder or a related interface. This can also be an IShellItemArray with a single element. /// [return: MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 0)] new object GetFolder(in Guid riid); /// Gets the identifier of a specific item in the folder view, by index. /// The index of the item in the view. /// The address of a pointer to a PIDL containing the item's identifier information. new PIDL Item([In] int iItemIndex); /// /// Gets the number of items in the folder. This can be the number of all items, or a subset such as the number of selected items. /// /// Flags from the _SVGIO enumeration that limit the count to certain types of items. /// The number of items (files and folders) displayed in the folder view. new int ItemCount([In] SVGIO uFlags); /// Gets the address of an enumeration object based on the collection of items in the folder view. /// _SVGIO values that limit the enumeration to certain types of items. /// Reference to the desired IID to represent the folder. /// /// When this method returns, contains the interface pointer requested in . This is typically an /// IEnumIDList, IDataObject, or IShellItemArray. If an error occurs, this value is NULL. /// [return: MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 1)] new object Items([In] SVGIO uFlags, in Guid riid); /// Gets the index of an item in the folder's view which has been marked by using the SVSI_SELECTIONMARK in IFolderView::SelectItem. /// The index of the marked item. new int GetSelectionMarkedItem(); /// Gets the index of the item that currently has focus in the folder's view. /// The index of the item. new int GetFocusedItem(); /// Gets the position of an item in the folder's view. /// A pointer to an ITEMIDLIST interface. /// The position of the item's upper-left corner. new POINT GetItemPosition([In] PIDL pidl); /// /// Gets a POINT structure containing the width (x) and height (y) dimensions, including the surrounding white space, of an item. /// /// The current sizing dimensions of the items in the folder's view. new POINT GetSpacing(); /// /// Gets a pointer to a POINT structure containing the default width (x) and height (y) measurements of an item, including the /// surrounding white space. /// /// The default sizing dimensions of the items in the folder's view. new POINT GetDefaultSpacing(); /// Gets the current state of the folder's Auto Arrange mode. /// Returns S_OK if the folder is in Auto Arrange mode; S_FALSE if it is not. [PreserveSig] new HRESULT GetAutoArrange(); /// Selects an item in the folder's view. /// The index of the item to select in the folder's view. /// One of the _SVSIF constants that specify the type of selection to apply. new void SelectItem([In] int iItem, [In] SVSIF dwFlags); /// Allows the selection and positioning of items visible in the folder's view. /// The number of items to select. /// A pointer to an array of size that contains the PIDLs of the items. /// /// A pointer to an array of structures containing the locations each corresponding element in should be positioned. /// /// One of the _SVSIF constants that specifies the type of selection to apply. new void SelectAndPositionItems([In] uint cidl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] apidl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] POINT[] apt, [In] SVSIF dwFlags); /// Groups the view by the given property key and direction. /// /// Type: REFPROPERTYKEY /// A PROPERTYKEY by which the view should be grouped. /// /// /// Type: BOOL /// A value of type BOOL to indicate sort order of the groups. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-setgroupby HRESULT // SetGroupBy( REFPROPERTYKEY key, BOOL fAscending ); void SetGroupBy(in PROPERTYKEY key, [MarshalAs(UnmanagedType.Bool)] bool fAscending); /// Retrieves the property and sort order used for grouping items in the folder display. /// /// Type: PROPERTYKEY* /// A pointer to the PROPERTYKEY by which the view is grouped. /// /// /// Type: BOOL* /// A pointer to a value of type BOOL that indicates sort order of the groups. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getgroupby HRESULT // GetGroupBy( PROPERTYKEY *pkey, BOOL *pfAscending ); void GetGroupBy(out PROPERTYKEY pkey, [MarshalAs(UnmanagedType.Bool)] out bool pfAscending); /// /// /// [This method is still implemented, but should be considered deprecated as of Windows 7. It might not be implemented in /// future versions of Windows. It cannot be used with items in search results or library views, so consider using the item's /// existing properties or, if applicable, emitting properties from your namespace or property handler. See Developing Property /// Handlers for Windows Search for more information.] /// /// Caches a property for an item in the view's property cache. /// /// /// Type: PCUITEMID_CHILD /// A PIDL that identifies the item. /// /// /// Type: REFPROPERTYKEY /// The PROPERTYKEY which is to be stored. /// /// /// Type: const PROPVARIANT* /// A pointer to a PROPVARIANT structure in which the PROPERTYKEY is stored. /// /// The property is displayed in the view, but not written to the underlying item. // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-setviewproperty // DEPRECATED_HRESULT SetViewProperty( PCUITEMID_CHILD pidl, REFPROPERTYKEY propkey, REFPROPVARIANT propvar ); [Obsolete] void SetViewProperty([In] PIDL pidl, in PROPERTYKEY propkey, [In] PROPVARIANT propvar); /// /// /// [This method is still implemented, but should be considered deprecated as of Windows 7. It might not be implemented in /// future versions of Windows. It cannot be used with items in search results or library views, so consider using the item's /// existing properties or, if applicable, emitting properties from your namespace or property handler. See Developing Property /// Handlers for Windows Search for more information.] /// /// Gets a property value for a given property key from the view's cache. /// /// /// Type: PCUITEMID_CHILD /// A pointer to an item identifier list (PIDL). /// /// /// Type: REFPROPERTYKEY /// The PROPERTYKEY to be retrieved. /// /// /// Type: PROPVARIANT* /// A pointer to a PROPVARIANT structure in which the PROPERTYKEY is stored. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getviewproperty // DEPRECATED_HRESULT GetViewProperty( PCUITEMID_CHILD pidl, REFPROPERTYKEY propkey, PROPVARIANT *ppropvar ); [Obsolete] void GetViewProperty([In] PIDL pidl, in PROPERTYKEY propkey, [In, Out] PROPVARIANT ppropvar); /// /// /// [This method is still implemented, but should be considered deprecated as of Windows 7. It might not be implemented in /// future versions of Windows. It cannot be used with items in search results or library views, so consider using the item's /// existing properties or, if applicable, emitting properties from your namespace or property handler. See Developing Property /// Handlers for Windows Search for more information.] /// /// Set the list of tile properties for an item. /// /// /// Type: PCUITEMID_CHILD /// A pointer to an item identifier list (PIDL). /// /// /// Type: LPCWSTR /// A pointer to a Unicode string containing a list of properties. /// /// /// The pszPropList parameter must be of the form "prop:<canonical-property-name>;<canonical-property-name>" where /// "<canonical-property-name>" is replaced by an actual canonical property name. The parameter can contain one or more /// properties delimited by semicolons. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-settileviewproperties // DEPRECATED_HRESULT SetTileViewProperties( PCUITEMID_CHILD pidl, LPCWSTR pszPropList ); [Obsolete] void SetTileViewProperties([In] PIDL pidl, [In, MarshalAs(UnmanagedType.LPWStr)] string pszPropList); /// /// /// [This method is still implemented, but should be considered deprecated as of Windows 7. It might not be implemented in /// future versions of Windows. It cannot be used with items in search results or library views, so consider using the item's /// existing properties or, if applicable, emitting properties from your namespace or property handler. See Developing Property /// Handlers for Windows Search for more information.] /// /// Sets the list of extended tile properties for an item. /// /// /// Type: PCUITEMID_CHILD /// A pointer to an item identifier list (PIDL). /// /// /// Type: LPCWSTR /// A pointer to a Unicode string containing a list of properties. /// /// /// The pszPropList parameter must be of the form "prop:<canonical-property-name>;<canonical-property-name>" where /// "<canonical-property-name>" is an actual canonical property name. It can contain one or more properties delimited by semicolons. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-setextendedtileviewproperties // DEPRECATED_HRESULT SetExtendedTileViewProperties( PCUITEMID_CHILD pidl, LPCWSTR pszPropList ); [Obsolete] void SetExtendedTileViewProperties([In] PIDL pidl, [In, MarshalAs(UnmanagedType.LPWStr)] string pszPropList); /// Sets the default text to be used when there are no items in the view. /// /// Type: FVTEXTTYPE /// This value should be set to the following flag. /// FVST_EMPTYTEXT /// Set the text to display when there are no items in the view. /// /// /// Type: LPCWSTR /// A pointer to a Unicode string that contains the text to be used. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-settext HRESULT SetText( // FVTEXTTYPE iType, LPCWSTR pwszText ); void SetText([In] FVTEXTTYPE iType, [In, MarshalAs(UnmanagedType.LPWStr)] string pwszText); /// Sets and applies specified folder flags. /// /// Type: DWORD /// The value of type DWORD that specifies the bitmask indicating which items in the structure are desired or valid. /// /// /// Type: DWORD /// The value of type DWORD that contains one or more FOLDERFLAGS. /// /// /// For Windows 7 or later: This method must be used in combination with the FVO_CUSTOMPOSITION flag from the /// FOLDERVIEWOPTIONS enumeration. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-setcurrentfolderflags // HRESULT SetCurrentFolderFlags( DWORD dwMask, DWORD dwFlags ); void SetCurrentFolderFlags([In] FOLDERFLAGS dwMask, [In] FOLDERFLAGS dwFlags); /// Gets the currently applied folder flags. /// /// Type: DWORD* /// A pointer to a DWORD with any FOLDERFLAGS that have been applied to the folder. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getcurrentfolderflags // HRESULT GetCurrentFolderFlags( DWORD *pdwFlags ); FOLDERFLAGS GetCurrentFolderFlags(); /// Gets the count of sort columns currently applied to the view. /// /// Type: int* /// A pointer to an int. /// /// Returns E_INVALIDARG if the column count provided does not equal the count of sort columns in the view. // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getsortcolumncount HRESULT // GetSortColumnCount( int *pcColumns ); int GetSortColumnCount(); /// Sets and sorts the view by the given sort columns. /// /// Type: const SORTCOLUMN* /// A pointer to a SORTCOLUMN structure. The size of this structure is determined by cColumns. /// /// /// Type: int /// The count of columns to sort by. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-setsortcolumns HRESULT // SetSortColumns( const SORTCOLUMN *rgSortColumns, int cColumns ); void SetSortColumns([In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] SORTCOLUMN[] rgSortColumns, [In] int cColumns); /// Gets the sort columns currently applied to the view. /// /// Type: const SORTCOLUMN* /// A pointer to a SORTCOLUMN structure. The size of this structure is determined by cColumns. /// /// /// Type: int /// The count of columns to sort by. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getsortcolumns HRESULT // GetSortColumns( SORTCOLUMN *rgSortColumns, int cColumns ); void GetSortColumns([In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] SORTCOLUMN[] rgSortColumns, [In] int cColumns); /// Retrieves an object that represents a specified item. /// /// Type: int /// The zero-based index of the item to retrieve. /// /// /// Type: REFIID /// Reference to the desired IID to represent the item, such as IID_IShellItem. /// /// /// Type: void** /// When this method returns, contains the interface pointer requested in . This is typically IShellItem. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getitem HRESULT GetItem( int // iItem, REFIID riid, void **ppv ); [return: MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 1)] object GetItem([In] int iItem, in Guid riid); /// Gets the next visible item in relation to a given index in the view. /// /// Type: int /// The zero-based position at which to start searching for a visible item. /// /// /// Type: BOOL /// TRUE to find the first visible item before iStart. FALSE to find the first visible item after iStart. /// /// /// Type: int* /// When this method returns, contains a pointer to a value that receives the index of the visible item in the view. /// /// /// Type: HRESULT /// This method can return one of these values. /// /// /// Return code /// Description /// /// /// S_OK /// Item retrieved. /// /// /// S_FALSE /// Item not found. Note that this is a success code. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getvisibleitem HRESULT // GetVisibleItem( int iStart, BOOL fPrevious, int *piItem ); [PreserveSig] HRESULT GetVisibleItem([In] int iStart, [In, MarshalAs(UnmanagedType.Bool)] bool fPrevious, out int piItem); /// Locates the currently selected item at or after a given index. /// The index position from which to start searching for the currently selected item. /// A pointer to a value that receives the index of the item in the view. /// /// Type: HRESULT /// Returns S_OK if a selected item was found, or an error value otherwise, including the following: /// /// /// Return code /// Description /// /// /// S_FALSE /// /// Item not found. Note that this is a success code. The operation was successful in searching the view, it simply did not find /// a currently selected item after the given index (iStart). It is possible that no item was selected, or that the selected /// item had an index less than iStart. /// /// /// /// [PreserveSig] HRESULT GetSelectedItem([In] int iStart, out int piItem); /// /// Gets the current selection as an IShellItemArray. /// /// /// Type: BOOL /// If TRUE, this method returns an IShellItemArray containing the parent folder when there is no current selection. /// /// /// Type: IShellItemArray** /// The address of a pointer to an IShellItemArray. /// /// /// Type: HRESULT /// Returns one of the following values, or an error otherwise. /// /// /// Return code /// Description /// /// /// S_OK /// The operation completed successfully. /// /// /// S_FALSE /// The IShellItemArray returned has zero items. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getselection HRESULT // GetSelection( BOOL fNoneImpliesFolder, IShellItemArray **ppsia ); [PreserveSig] HRESULT GetSelection([In, MarshalAs(UnmanagedType.Bool)] bool fNoneImpliesFolder, out IShellItemArray ppsia); /// Gets the selection state including check state. /// /// Type: PCUITEMID_CHILD /// A PIDL of the item. /// /// /// Type: DWORD* /// /// Zero or one of the following _SVSIF constants that specify the current type of selection: SVSI_FOCUSED, /// SVSI_SELECT, SVSI_CHECK, or SVSI_CHECK2. Other _SVSIF constants are not returned by this API. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getselectionstate HRESULT // GetSelectionState( PCUITEMID_CHILD pidl, DWORD *pdwFlags ); SVSIF GetSelectionState([In] PIDL pidl); /// Invokes the given verb on the current selection. /// /// Type: LPCSTR /// A pointer to a Unicode string containing a verb. /// /// If pszVerb is NULL, then the default verb is invoked on the selection. // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-invokeverbonselection // HRESULT InvokeVerbOnSelection( LPCSTR pszVerb ); void InvokeVerbOnSelection([In, MarshalAs(UnmanagedType.LPWStr)] string pszVerb); /// Sets and applies the view mode and image size. /// /// Type: FOLDERVIEWMODE /// The FOLDERVIEWMODE to be applied. /// /// /// Type: int /// The size of the image in pixels. /// /// If iImageSize is -1 then the current default icon size for the view mode is used. // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-setviewmodeandiconsize // HRESULT SetViewModeAndIconSize( FOLDERVIEWMODE uViewMode, int iImageSize ); void SetViewModeAndIconSize([In] FOLDERVIEWMODE uViewMode, [In] int iImageSize = -1); /// Gets the current view mode and icon size applied to the view. /// /// Type: FOLDERVIEWMODE* /// A pointer to the current FOLDERVIEWMODE. /// /// /// Type: int* /// A pointer to the size of the icon in pixels. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getviewmodeandiconsize // HRESULT GetViewModeAndIconSize( FOLDERVIEWMODE *puViewMode, int *piImageSize ); void GetViewModeAndIconSize(out FOLDERVIEWMODE puViewMode, out int piImageSize); /// Turns on group subsetting and sets the number of visible rows of items in each group. /// /// Type: UINT /// The number of rows to be visible. /// /// If cVisibleRows is zero, subsetting is turned off. // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-setgroupsubsetcount HRESULT // SetGroupSubsetCount( UINT cVisibleRows ); void SetGroupSubsetCount([In] uint cVisibleRows); /// Gets the count of visible rows displayed for a group's subset. /// /// Type: UINT* /// The number of rows currently visible. /// /// If group subsetting is disabled the number of rows is zero. // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getgroupsubsetcount HRESULT // GetGroupSubsetCount( UINT *pcVisibleRows ); uint GetGroupSubsetCount(); /// Sets redraw on and off. /// /// Type: BOOL /// a BOOL value. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-setredraw HRESULT SetRedraw( // BOOL fRedrawOn ); void SetRedraw([In, MarshalAs(UnmanagedType.Bool)] bool fRedrawOn); /// /// Checks to see if this view sourced the current drag-and-drop or cut-and-paste operation (used by drop target objects). /// /// /// Type: HRESULT /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-ismoveinsamefolder HRESULT // IsMoveInSameFolder( ); [PreserveSig] HRESULT IsMoveInSameFolder(); /// Starts a rename operation on the current selection. // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-dorename HRESULT DoRename( ); void DoRename(); } /// Exposes a method that hosts an IFolderView object in a window. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl/nn-shobjidl-ifolderviewhost [PInvokeData("shobjidl.h", MSDNShortId = "NN:shobjidl.IFolderViewHost")] [ComImport, Guid("1ea58f02-d55a-411d-b09e-9e65ac21605b"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(FolderViewHost))] public interface IFolderViewHost { /// Initializes the object that hosts an IFolderView object. /// /// Type: HWND /// The handle of the window that contains the IFolderViewHost object. /// /// /// Type: IDataObject* /// The address of a pointer to a data object. /// /// /// Type: RECT* /// The address of a pointer to a RECT structure that specifies the dimensions of the folder view. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl/nf-shobjidl-ifolderviewhost-initialize HRESULT Initialize( HWND // hwndParent, IDataObject *pdo, RECT *prc ); void Initialize([In] HWND hwndParent, [In] IDataObject pdo, in RECT prc); } /// Exposes methods to obtain folder view settings. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ifolderviewsettings [ComImport, Guid("ae8c987d-8797-4ed3-be72-2a47dd938db0"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IFolderViewSettings { /// Gets an ordered list of columns that corresponds to the column enumerated. /// A reference to the interface identifier (IID) of the IPropertyDescriptionList. /// /// Type: IPropertyDescriptionList** /// The address of an IPropertyDescriptionList interface pointer. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ifolderviewsettings-getcolumnpropertylist // HRESULT GetColumnPropertyList( REFIID riid, void **ppv ); IPropertyDescriptionList GetColumnPropertyList(in Guid riid); /// Gets a grouping property. /// /// Type: PROPERTYKEY* /// A pointer to a PROPERTYKEY structure indicating the key by which content is grouped. /// /// /// Type: BOOL* /// A pointer to a value indicating whether grouping order is ascending. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ifolderviewsettings-getgroupbyproperty // HRESULT GetGroupByProperty( PROPERTYKEY *pkey, BOOL *pfGroupAscending ); void GetGroupByProperty(out PROPERTYKEY pkey, [MarshalAs(UnmanagedType.Bool)] out bool pfGroupAscending); /// Gets a folder's logical view mode. /// /// Type: FOLDERLOGICALVIEWMODE* /// A pointer to a FOLDERLOGICALVIEWMODE value. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ifolderviewsettings-getviewmode HRESULT // GetViewMode( FOLDERLOGICALVIEWMODE *plvm ); FOLDERLOGICALVIEWMODE GetViewMode(); /// Gets the folder icon size. /// /// Type: UINT* /// A pointer to the icon size. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ifolderviewsettings-geticonsize HRESULT // GetIconSize( UINT *puIconSize ); uint GetIconSize(); /// Gets folder view options flags. /// /// Type: FOLDERFLAGS* /// A pointer to a mask for folder view options. /// /// /// Type: FOLDERFLAGS* /// A pointer to a flag for folder view options. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ifolderviewsettings-getfolderflags HRESULT // GetFolderFlags( FOLDERFLAGS *pfolderMask, FOLDERFLAGS *pfolderFlags ); void GetFolderFlags(out FOLDERFLAGS pfolderMask, out FOLDERFLAGS pfolderFlags); /// Gets sort column information. /// /// Type: SORTCOLUMN* /// A pointer to an array of SORTCOLUMN structures. /// /// /// Type: UINT /// The source column count. /// /// /// Type: UINT* /// A pointer to the rgSortColumns array length. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ifolderviewsettings-getsortcolumns HRESULT // GetSortColumns( SORTCOLUMN *rgSortColumns, UINT cColumnsIn, UINT *pcColumnsOut ); void GetSortColumns([Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] SORTCOLUMN[] rgSortColumns, uint cColumnsIn, out uint pcColumnsOut); /// Gets group count for visible rows. /// /// Type: UINT* /// A pointer to group count. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ifolderviewsettings-getgroupsubsetcount // HRESULT GetGroupSubsetCount( UINT *pcVisibleRows ); uint GetGroupSubsetCount(); } /// /// Exposes methods that hold items from a data object. /// /// An IResultsFolder is a folder that can hold items from all over the namespace and represent them to the user in a single folder. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl/nn-shobjidl-iresultsfolder [PInvokeData("shobjidl.h", MSDNShortId = "db44052b-bd26-412f-9f2a-66a0c53b65ac")] [ComImport, Guid("96E5AE6D-6AE1-4b1c-900C-C6480EAA8828"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IResultsFolder { /// Adds an item to a results folder. /// /// Type: IShellItem* /// A pointer to an IShellItem. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl/nf-shobjidl-iresultsfolder-additem HRESULT AddItem( IShellItem // *psi ); void AddItem([In] IShellItem psi); /// Inserts a pointer to an item identifier list (PIDL) into a results folder. /// /// Type: PCIDLIST_ABSOLUTE /// A pointer to the IDList of the given object relative to the Desktop. /// /// /// Type: PITEMID_CHILD* /// A PIDL consisting of 0 or 1 SHITEMID structures, relative to a parent folder. This parameter maybe NULL. /// /// /// The PIDL received represents the item that was just added and is a unique representation of this item generated by this /// results folder. It is only valid when used in reference to this results folder and should not be combined with a PIDL to /// another folder, including the folder this item originally came from. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl/nf-shobjidl-iresultsfolder-addidlist HRESULT AddIDList( // PCIDLIST_ABSOLUTE pidl, PITEMID_CHILD *ppidlAdded ); void AddIDList([In] PIDL pidl, out PIDL ppidlAdded); /// Removes an item from a results folder. /// /// Type: IShellItem* /// A pointer to an IShellItem. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl/nf-shobjidl-iresultsfolder-removeitem HRESULT RemoveItem( // IShellItem *psi ); void RemoveItem([In] IShellItem psi); /// Removes a pointer to an item identifier list (PIDL) from a results folder. /// /// Type: PCIDLIST_ABSOLUTE /// A PIDL relative to the Desktop. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl/nf-shobjidl-iresultsfolder-removeidlist HRESULT RemoveIDList( // PCIDLIST_ABSOLUTE pidl ); void RemoveIDList([In] PIDL pidl); /// Removes all items from a results folder. // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl/nf-shobjidl-iresultsfolder-removeall HRESULT RemoveAll( ); void RemoveAll(); } /// Extension method to simplify using the method. /// Type of the interface to get. /// An instance. /// Receives the interface pointer requested in . public static T GetFolder(this IFolderView fv) where T : class => (T)fv.GetFolder(typeof(T).GUID); /// Extension method to simplify using the method. /// Type of the interface to get. /// An instance. /// /// Type: int /// The zero-based index of the item to retrieve. /// /// Receives the interface pointer requested in . public static T GetItem(this IFolderView2 fv, int iItem) where T : class { try { return (T)fv.GetItem(iItem, typeof(T).GUID); } catch { return null; } } /// Extension method to simplify using the method. /// Type of the interface to get. /// An instance. /// _SVGIO values that limit the enumeration to certain types of items. /// Receives the interface pointer requested in . public static T Items(this IFolderView fv, SVGIO uFlags) where T : class => (T)fv.Items(uFlags, typeof(T).GUID); /// Extension method to simplify using the method. /// Type of the interface to get. /// An instance. /// /// Type: int /// The zero-based index of the item to retrieve. /// /// The interface pointer requested in . /// if the item is found; otherwise. public static bool TryGetItem(this IFolderView2 fv, int iItem, out T item) where T : class { try { item = (T)fv.GetItem(iItem, typeof(T).GUID); return true; } catch { item = null; return false; } } /// /// Defines column information. Used by members of the IColumnManager interface. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/ns-shobjidl_core-cm_columninfo typedef struct CM_COLUMNINFO { // DWORD cbSize; DWORD dwMask; DWORD dwState; UINT uWidth; UINT uDefaultWidth; UINT uIdealWidth; WCHAR wszName[80]; } CM_COLUMNINFO; [PInvokeData("shobjidl_core.h", MSDNShortId = "b4437aa7-9682-4819-a353-936179e84005")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct CM_COLUMNINFO { /// /// Type: DWORD /// The size of the structure, in bytes. /// public uint cbSize; /// /// Type: DWORD /// One or more values from the CM_MASK enumeration that specify which members of this structure are valid. /// public CM_MASK dwMask; /// /// Type: DWORD /// One or more values from the CM_STATE enumeration that specify the state of the column. /// public CM_STATE dwState; /// /// Type: UINT /// One of the members of the CM_SET_WIDTH_VALUE enumeration that specifies the column width. /// public CM_SET_WIDTH_VALUE uWidth; /// /// Type: UINT /// The default width of the column. /// public uint uDefaultWidth; /// /// Type: UINT /// The ideal width of the column. /// public uint uIdealWidth; /// /// Type: WCHAR[MAX_COLUMN_NAME_LEN] /// A buffer of size MAX_COLUMN_NAME_LEN that contains the name of the column as a null-terminated Unicode string. /// [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_COLUMN_NAME_LEN)] public string wszName; /// Initializes a new instance of the struct for retrieval of specified items. /// The mask of items to retrieve. public CM_COLUMNINFO(CM_MASK mask) : this() { cbSize = (uint)Marshal.SizeOf(this); dwMask = mask; } } /// Stores information about how to sort a column that is displayed in the folder view. /// /// Each column displayed in the folder view (for example, "details" view mode), is associated with a property that has a /// PROPERTYKEY ID. When you want to sort the view by a particular property, you specify the property key for that property. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/ns-shobjidl_core-sortcolumn typedef struct SORTCOLUMN { // PROPERTYKEY propkey; SORTDIRECTION direction; } SORTCOLUMN; [PInvokeData("shobjidl_core.h", MSDNShortId = "3ca4c318-6462-4e22-813c-ef7b3ef03230")] [StructLayout(LayoutKind.Sequential)] public struct SORTCOLUMN { /// /// Type: PROPERTYKEY /// /// The ID of the column by which the user will sort. A PROPERTYKEY structure. For example, for the "Name" column, the property /// key is PKEY_ItemNameDisplay. /// /// public PROPERTYKEY propkey; /// /// Type: SORTDIRECTION /// The direction in which the items are sorted. One of the following values. /// SORT_DESCENDING /// /// The items are sorted in ascending order. Whether the sort is alphabetical, numerical, and so on, is determined by the data /// type of the column indicated in propkey. /// /// SORT_ASCENDING /// /// The items are sorted in descending order. Whether the sort is alphabetical, numerical, and so on, is determined by the data /// type of the column indicated in propkey. /// /// public SORTDIRECTION direction; } /// CoClass for IFolderViewHost [PInvokeData("shobjidl.h")] [ComImport, Guid("20b1cb23-6968-4eb9-b7d4-a66d00d07cee"), ClassInterface(ClassInterfaceType.None)] public class FolderViewHost { } } }