diff --git a/PInvoke/Ole/Ole32/OleIdl.cs b/PInvoke/Ole/Ole32/OleIdl.cs index 5f973af8..d599f063 100644 --- a/PInvoke/Ole/Ole32/OleIdl.cs +++ b/PInvoke/Ole/Ole32/OleIdl.cs @@ -10,6 +10,7 @@ namespace Vanara.PInvoke /// The IOleWindow interface provides methods that allow an application to obtain the handle to the various windows that participate in in-place /// activation, and also to enter and exit context-sensitive help mode. /// + [PInvokeData("Oleidl.h")] [ComImport, Guid("00000114-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IOleWindow { @@ -22,5 +23,21 @@ namespace Vanara.PInvoke /// true if help mode should be entered; false if it should be exited. void ContextSensitiveHelp([MarshalAs(UnmanagedType.Bool)] bool fEnterMode); } + + /// + /// Indicates the number of menu items in each of the six menu groups of a menu shared between a container and an object server during an in-place + /// editing session. This is the mechanism for building a shared menu. + /// + [PInvokeData("Oleidl.h", MSDNShortId = "ms693766")] + [StructLayout(LayoutKind.Sequential)] + public struct OLEMENUGROUPWIDTHS + { + /// + /// An array whose elements contain the number of menu items in each of the six menu groups of a shared in-place editing menu. Each menu group can + /// have any number of menu items. The container uses elements 0, 2, and 4 to indicate the number of menu items in its File, View, and Window menu + /// groups. The object server uses elements 1, 3, and 5 to indicate the number of menu items in its Edit, Object, and Help menu groups. + /// + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] public uint[] width; + } } } \ No newline at end of file diff --git a/PInvoke/Shell32/ShObjIdl.IShellItem.cs b/PInvoke/Shell32/ShObjIdl.IShellItem.cs index c9f37f31..11267dbc 100644 --- a/PInvoke/Shell32/ShObjIdl.IShellItem.cs +++ b/PInvoke/Shell32/ShObjIdl.IShellItem.cs @@ -298,36 +298,74 @@ namespace Vanara.PInvoke SIGDN_URL = 0x80068000 } - /// Flags for . - [Flags] - public enum SIIGBF - { - /// Shrink the bitmap as necessary to fit, preserving its aspect ratio. - SIIGBF_RESIZETOFIT = 0x00000000, - /// Passed by callers if they want to stretch the returned image themselves. For example, if the caller passes an icon size of 80x80, a 96x96 thumbnail could be returned. This action can be used as a performance optimization if the caller expects that they will need to stretch the image. Note that the Shell implementation of IShellItemImageFactory performs a GDI stretch blit. If the caller wants a higher quality image stretch than provided through that mechanism, they should pass this flag and perform the stretch themselves. - SIIGBF_BIGGERSIZEOK = 0x00000001, - /// Return the item only if it is already in memory. Do not access the disk even if the item is cached. Note that this only returns an already-cached icon and can fall back to a per-class icon if an item has a per-instance icon that has not been cached. Retrieving a thumbnail, even if it is cached, always requires the disk to be accessed, so GetImage should not be called from the UI thread without passing SIIGBF_MEMORYONLY. - SIIGBF_MEMORYONLY = 0x00000002, - /// Return only the icon, never the thumbnail. - SIIGBF_ICONONLY = 0x00000004, - /// Return only the thumbnail, never the icon. Note that not all items have thumbnails, so SIIGBF_THUMBNAILONLY will cause the method to fail in these cases. - SIIGBF_THUMBNAILONLY = 0x00000008, - /// Allows access to the disk, but only to retrieve a cached item. This returns a cached thumbnail if it is available. If no cached thumbnail is available, it returns a cached per-instance icon but does not extract a thumbnail or icon. - SIIGBF_INCACHEONLY = 0x00000010, - /// Introduced in Windows 8. If necessary, crop the bitmap to a square. - SIIGBF_CROPTOSQUARE = 0x00000020, - /// Introduced in Windows 8. Stretch and crop the bitmap to a 0.7 aspect ratio. - SIIGBF_WIDETHUMBNAILS = 0x00000040, - /// Introduced in Windows 8. If returning an icon, paint a background using the associated app's registered background color. - SIIGBF_ICONBACKGROUND = 0x00000080, - /// Introduced in Windows 8. If necessary, stretch the bitmap so that the height and width fit the given size. - SIIGBF_SCALEUP = 0x00000100, - } + /// Flags for . + [Flags] + public enum SIIGBF + { + /// Shrink the bitmap as necessary to fit, preserving its aspect ratio. + SIIGBF_RESIZETOFIT = 0x00000000, + /// Passed by callers if they want to stretch the returned image themselves. For example, if the caller passes an icon size of 80x80, a 96x96 thumbnail could be returned. This action can be used as a performance optimization if the caller expects that they will need to stretch the image. Note that the Shell implementation of IShellItemImageFactory performs a GDI stretch blit. If the caller wants a higher quality image stretch than provided through that mechanism, they should pass this flag and perform the stretch themselves. + SIIGBF_BIGGERSIZEOK = 0x00000001, + /// Return the item only if it is already in memory. Do not access the disk even if the item is cached. Note that this only returns an already-cached icon and can fall back to a per-class icon if an item has a per-instance icon that has not been cached. Retrieving a thumbnail, even if it is cached, always requires the disk to be accessed, so GetImage should not be called from the UI thread without passing SIIGBF_MEMORYONLY. + SIIGBF_MEMORYONLY = 0x00000002, + /// Return only the icon, never the thumbnail. + SIIGBF_ICONONLY = 0x00000004, + /// Return only the thumbnail, never the icon. Note that not all items have thumbnails, so SIIGBF_THUMBNAILONLY will cause the method to fail in these cases. + SIIGBF_THUMBNAILONLY = 0x00000008, + /// Allows access to the disk, but only to retrieve a cached item. This returns a cached thumbnail if it is available. If no cached thumbnail is available, it returns a cached per-instance icon but does not extract a thumbnail or icon. + SIIGBF_INCACHEONLY = 0x00000010, + /// Introduced in Windows 8. If necessary, crop the bitmap to a square. + SIIGBF_CROPTOSQUARE = 0x00000020, + /// Introduced in Windows 8. Stretch and crop the bitmap to a 0.7 aspect ratio. + SIIGBF_WIDETHUMBNAILS = 0x00000040, + /// Introduced in Windows 8. If returning an icon, paint a background using the associated app's registered background color. + SIIGBF_ICONBACKGROUND = 0x00000080, + /// Introduced in Windows 8. If necessary, stretch the bitmap so that the height and width fit the given size. + SIIGBF_SCALEUP = 0x00000100, + } - /// - /// Exposes methods that retrieve information about a Shell item. IShellItem and IShellItem2 are the preferred representations of items in any new code. - /// - [SuppressUnmanagedCodeSecurity] + /// Exposes enumeration of IShellItem interfaces. This interface is typically obtained by calling the IEnumShellItems method. + [SuppressUnmanagedCodeSecurity] + [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("70629033-e363-4a28-a567-0db78006e6d7")] + [PInvokeData("Shobjidl.h", MSDNShortId = "bb761962")] + public interface IEnumShellItems + { + /// Gets an array of one or more IShellItem interfaces from the enumeration. + /// The number of elements in the array referenced by the rgelt parameter. + /// + /// The address of an array of pointers to IShellItem interfaces that receive the enumerated item or items. The calling application is responsible + /// for freeing the IShellItem interfaces by calling the IUnknown::Release method. + /// + /// + /// A pointer to a value that receives the number of IShellItem interfaces successfully retrieved. The count can be smaller than the value specified + /// in the celt parameter. This parameter can be NULL on entry only if celt is one, because in that case the method can only retrieve one item and + /// return S_OK, or zero items and return S_FALSE. + /// + /// + /// Returns S_OK if the method successfully retrieved the requested celt elements. This method only returns S_OK if the full count of requested items + /// are successfully retrieved. S_FALSE indicates that more items were requested than remained in the enumeration. The value pointed to by the + /// pceltFetched parameter specifies the actual number of items retrieved. Note that the value will be 0 if there are no more items to retrieve. + /// + [PreserveSig] + HRESULT Next(uint celt, [Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Interface, SizeParamIndex = 2)] IShellItem[] rgelt, out uint pceltFetched); + + /// Skips the specified number of elements in the enumeration sequence. + /// The number of IShellItem interfaces to skip. + void Skip(uint celt); + + /// Returns to the beginning of the enumeration sequence. + void Reset(); + + /// Gets a copy of the current enumeration. + /// The address of a pointer that receives a copy of this enumeration. + [return: MarshalAs(UnmanagedType.Interface)] + IEnumShellItems Clone(); + } + + /// + /// Exposes methods that retrieve information about a Shell item. IShellItem and IShellItem2 are the preferred representations of items in any new code. + /// + [SuppressUnmanagedCodeSecurity] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")] [PInvokeData("Shobjidl.h", MSDNShortId = "bb761144")] public interface IShellItem @@ -578,12 +616,12 @@ namespace Vanara.PInvoke IEnumShellItems EnumItems(); } - /// - /// - /// - [ComImport, Guid("bcc18b79-ba16-442f-80c4-8a59c30c463b"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - public interface IShellItemImageFactory - { + /// + /// + /// + [ComImport, Guid("bcc18b79-ba16-442f-80c4-8a59c30c463b"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface IShellItemImageFactory + { /// Gets an HBITMAP that represents an IShellItem. The default behavior is to load a thumbnail. If there is no thumbnail for the current IShellItem, it retrieves an HBITMAP for the icon of the item. The thumbnail or icon is extracted if it is not currently cached. /// A structure that specifies the size of the image to be received. /// One or more of the SIIGBF flags. @@ -591,6 +629,6 @@ namespace Vanara.PInvoke /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. [PreserveSig] HRESULT GetImage([In, MarshalAs(UnmanagedType.Struct)] SIZE size, [In] SIIGBF flags, out Gdi32.SafeObjectHandle phbm); - } - } + } + } } \ No newline at end of file diff --git a/PInvoke/Shell32/ShObjIdl.IShellView.cs b/PInvoke/Shell32/ShObjIdl.IShellView.cs index 4459584a..4e028763 100644 --- a/PInvoke/Shell32/ShObjIdl.IShellView.cs +++ b/PInvoke/Shell32/ShObjIdl.IShellView.cs @@ -1,6 +1,7 @@ using System; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; +using Vanara.Extensions; using static Vanara.PInvoke.Ole32; // ReSharper disable MemberCanBePrivate.Global @@ -15,11 +16,17 @@ namespace Vanara.PInvoke { public static partial class Shell32 { + /// Specifies an application-defined callback function that a property sheet extension uses to add a page to a property sheet. + /// Handle to a property sheet page. + /// Application-defined 32-bit value. + /// Returns TRUE if successful, or FALSE otherwise. + [PInvokeData("Prsht.h")] [UnmanagedFunctionPointer(CallingConvention.Winapi, SetLastError = true, CharSet = CharSet.Unicode)] [System.Security.SuppressUnmanagedCodeSecurity] [return: MarshalAs(UnmanagedType.Bool)] public delegate bool AddPropSheetPageProc(IntPtr hpage, IntPtr lParam); + /// Flags specifying where the toolbar buttons should go. [Flags] public enum FCT : uint { @@ -31,20 +38,25 @@ namespace Vanara.PInvoke FCT_ADDTOEND = 0x0004, } + /// + /// A value that indicates the frame control to show or hide. One of the following values as defined in Shobjidl.h or -1 for fullscreen/kiosk mode. + /// [Flags] public enum FCW : uint { + /// The browser's media bar. FCW_INTERNETBAR = 0x0006, - /// Retrieves the window handle to the browser's progress bar. + /// The browser's progress bar. FCW_PROGRESS = 0x0008, - /// Retrieves the window handle to the browser's status bar. + /// The browser's status bar. FCW_STATUS = 0x0001, - /// Retrieves the window handle to the browser's toolbar. + /// The browser's toolbar. FCW_TOOLBAR = 0x0002, - /// Retrieves the window handle to the browser's tree view. + /// The browser's tree view. FCW_TREE = 0x0003, } + /// Folder view flags. [Flags] public enum FOLDERFLAGS : uint { @@ -116,6 +128,7 @@ namespace Vanara.PInvoke FWF_ALLOWRTLREADING = 0x80000000, } + /// The view mode of a folder. public enum FOLDERVIEWMODE { /// The view should determine the best option. @@ -138,6 +151,29 @@ namespace Vanara.PInvoke FVM_TILE = 6, } + /// + /// Used by methods of the IFolderViewOptions interface to activate Windows Vista options not supported by default in Windows 7 and later systems as well as deactivating new Windows 7 options. + /// + [Flags] + public enum FOLDERVIEWOPTIONS + { + /// Do not use any special options. + FVO_DEFAULT = 0x00000000, + /// Use the Windows Vista list view. This can be used to maintain continuity between systems so that users are presented with an expected view. At this time, setting this flag has the effective, though not literal, result of the application of the FVO_CUSTOMPOSITION and FVO_CUSTOMORDERING flags. However, this could change. Applications should be specific about the behaviors that they require. For instance, if an application requires custom positioning of its items, it should not rely on FVO_VISTALAYOUT to provide it, but instead explicitly apply the FVO_CUSTOMPOSITION flag. + FVO_VISTALAYOUT = 0x00000001, + /// Items require custom positioning within the space of the view. Those items are positioned to specific coordinates. This option is not active by default in the Windows 7 view. + FVO_CUSTOMPOSITION = 0x00000002, + /// Items require custom ordering within the view. This option is not active by default in the Windows 7 view. When it is active, the user can reorder the view by dragging items to their desired locations. + FVO_CUSTOMORDERING = 0x00000004, + /// Tiles and Details displays can contain hyperlinks. This option is not active by default in the Windows 7 view. When hyperlinks are displayed, they are updated to the Windows 7 view. + FVO_SUPPORTHYPERLINKS = 0x00000008, + /// Do not display animations in the view. This option was introduced in Windows 7 and is active by default in the Windows 7 view. + FVO_NOANIMATIONS = 0x00000010, + /// Do not show scroll tips. This option was introduced in Windows 7 and is active by default in the Windows 7 view. + FVO_NOSCROLLTIPS = 0x00000020, + } + + /// Flags specifying the folder to be browsed. [Flags] public enum SBSP : uint { @@ -226,9 +262,12 @@ namespace Vanara.PInvoke SBSP_WRITENOHISTORY = 0x08000000 } + /// The type of view requested. public enum SV2GV : int { + /// Current Shell view. SV2GV_CURRENTVIEW = -1, + /// Default Shell view. SV2GV_DEFAULTVIEW = -2, } @@ -245,6 +284,7 @@ namespace Vanara.PInvoke SV3CVW3_FORCEFOLDERFLAGS = 0x00000004, } + /// Selection flags for IShellView objects. [Flags] public enum SVSIF : uint { @@ -289,6 +329,26 @@ namespace Vanara.PInvoke SVUIA_INPLACEACTIVATE = 3 } + /// Exposes methods that allow control of folder view options specific to the Windows 7 and later views. + [PInvokeData("Shobjidl.h", MinClient = PInvokeClient.Windows7)] + [ComImport, Guid("3cc974d2-b302-4d36-ad3e-06d93f695d3f"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface IFolderViewOptions + { + /// Sets specified options for the view. + /// A bitmask made up of one or more of the FOLDERVIEWOPTIONS flags to indicate which options' are being changed. Values in fvoFlags not included in this mask are ignored. + /// A bitmask that contains the new values for the options specified in fvoMask. To enable an option, the bitmask should include the FOLDERVIEWOPTIONS flag for that option. To disable an option, the bit used for that FOLDERVIEWOPTIONS flag should be 0. + void SetFolderViewOptions(FOLDERVIEWOPTIONS fvoMask, FOLDERVIEWOPTIONS fvoFlags); + /// Retrieves the current set of options for the view. + /// A bitmask that, when this method returns successfully, receives the FOLDERVIEWOPTIONS values that are currently set. + FOLDERVIEWOPTIONS GetFolderViewOptions(); + } + + /// + /// Implemented by hosts of Shell views (objects that implement IShellView). Exposes methods that provide services for the view it is hosting and other + /// objects that run in the context of the Explorer window. + /// + /// + [PInvokeData("Shobjidl.h")] [ComImport, Guid("000214E2-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IShellBrowser : IOleWindow { @@ -298,24 +358,65 @@ namespace Vanara.PInvoke /// Determines whether context-sensitive help mode should be entered during an in-place activation session. /// true if help mode should be entered; false if it should be exited. new void ContextSensitiveHelp([MarshalAs(UnmanagedType.Bool)] bool fEnterMode); + /// Allows the container to insert its menu groups into the composite menu that is displayed when an extended namespace is being viewed or used. + /// A handle to an empty menu. + /// The address of an OLEMENUGROUPWIDTHS array of six LONG values. The container fills in elements 0, 2, and 4 to reflect the number of menu elements it provided in the File, View, and Window menu groups. void InsertMenusSB(IntPtr hmenuShared, ref OLEMENUGROUPWIDTHS lpMenuWidths); + /// Installs the composite menu in the view window. + /// A handle to the composite menu constructed by calls to IShellBrowser::InsertMenusSB and the InsertMenu function. + /// + /// The view's window handle. void SetMenuSB(IntPtr hmenuShared, IntPtr holemenuRes, IntPtr hwndActiveObject); + /// Permits the container to remove any of its menu elements from the in-place composite menu and to free all associated resources. + /// A handle to the in-place composite menu that was constructed by calls to IShellBrowser::InsertMenusSB and the InsertMenu function. void RemoveMenusSB(IntPtr hmenuShared); + /// Sets and displays status text about the in-place object in the container's frame-window status bar. + /// A pointer to a null-terminated character string that contains the message to display. void SetStatusTextSB([MarshalAs(UnmanagedType.LPWStr)] string pszStatusText); + /// Tells Windows Explorer to enable or disable its modeless dialog boxes. + /// Specifies whether the modeless dialog boxes are to be enabled or disabled. If this parameter is nonzero, modeless dialog boxes are enabled. If this parameter is zero, modeless dialog boxes are disabled. void EnableModelessSB([MarshalAs(UnmanagedType.Bool)] bool fEnable); + /// Translates accelerator keystrokes intended for the browser's frame while the view is active. + /// The address of an MSG structure containing the keystroke message. + /// The command identifier value corresponding to the keystroke in the container-provided accelerator table. Containers should use this value instead of translating again. void TranslateAcceleratorSB(ref MSG pmsg, ushort wID); + /// Informs Windows Explorer to browse to another folder. + /// The address of an ITEMIDLIST (item identifier list) structure that specifies an object's location. This value is dependent on the flag or flags set in the wFlags parameter. + /// Flags specifying the folder to be browsed. void BrowseObject(PIDL pidl, SBSP wFlags); + /// Gets an IStream interface that can be used for storage of view-specific state information. + /// Read/write access of the IStream interface. + /// The address that receives the IStream interface pointer. [return: MarshalAs(UnmanagedType.Interface)] IStream GetViewStateStream(STGM grfMode); + /// Gets the window handle to a browser control. + /// The control handle that is being requested. + /// The address of the window handle to the Windows Explorer control. IntPtr GetControlWindow(FCW id); + /// Sends control messages to either the toolbar or the status bar in a Windows Explorer window. + /// An identifier for either a toolbar (FCW_TOOLBAR) or for a status bar window (FCW_STATUS). + /// The message to be sent to the control. + /// The value depends on the message specified in the uMsg parameter. + /// The value depends on the message specified in the uMsg parameter. + /// The address of the return value of the SendMessage function. IntPtr SendControlMsg(FCW id, uint uMsg, IntPtr wParam, IntPtr lParam); - void QueryActiveShellView(ref IShellView ppshv); + /// Retrieves the currently active (displayed) Shell view object. + /// The address of the pointer to the currently active Shell view object. + [return: MarshalAs(UnmanagedType.Interface)] + IShellView QueryActiveShellView(); + /// Called by the Shell view when the view window or one of its child windows gets the focus or becomes active. + /// Address of the view object's IShellView pointer. void OnViewWindowActive(IShellView ppshv); - void SetToolbarItems(IntPtr lpButtons, uint nButtons, FCT uFlags); + /// This method has no effect on Windows Vista or later operating systems. Adds toolbar items to Windows Explorer's toolbar. + /// The address of an array of TBBUTTON structures. + /// The number of TBBUTTON structures in the lpButtons array. + /// Flags specifying where the toolbar buttons should go. + void SetToolbarItems([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] ComCtl32.TBBUTTON[] lpButtons, uint nButtons, FCT uFlags); } /// Exposes methods that present a view in the Windows Explorer or folder windows. /// + [PInvokeData("Shobjidl.h")] [ComImport, Guid("000214E3-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IShellView : IOleWindow { @@ -328,6 +429,8 @@ namespace Vanara.PInvoke /// Translates keyboard shortcut (accelerator) key strokes when a namespace extension's view has the focus. /// The address of the message to be translated. void TranslateAccelerator(ref MSG lpmsg); + /// Enables or disables modeless dialog boxes. This method is not currently implemented. + /// true to enable modeless dialog box windows or false to disable them. void EnableModeless([MarshalAs(UnmanagedType.Bool)] bool enable); /// /// Called when the activation state of the view window is changed by an event that is not caused by the Shell view itself. For example, if the TAB @@ -364,7 +467,7 @@ namespace Vanara.PInvoke void SaveViewState(); /// Changes the selection state of one or more items within the Shell view window. /// The address of the ITEMIDLIST structure. - /// One of the _SVSIF constants that specify the type of selection to apply. + /// One of the _SVSIF constants that specify the type of selection to apply. void SelectItem(PIDL pidlItem, SVSIF uFlags); /// Gets an interface that refers to data presented in the view. /// The constants that refer to an aspect of the view. @@ -373,11 +476,15 @@ namespace Vanara.PInvoke [return: MarshalAs(UnmanagedType.IUnknown)] object GetItemObject(SVGIO uItem, [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid); } + /// Extends the capabilities of IShellView. /// + [PInvokeData("Shobjidl.h")] [ComImport, Guid("88E39E80-3578-11CF-AE69-08002B2E1262"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IShellView2 : IShellView { + /// Retrieves a handle to one of the windows participating in in-place activation (frame, document, parent, or in-place object window). + /// A pointer to a variable that receives the window handle. new IntPtr GetWindow(); /// Determines whether context-sensitive help mode should be entered during an in-place activation session. /// true if help mode should be entered; false if it should be exited. @@ -385,6 +492,8 @@ namespace Vanara.PInvoke /// Translates keyboard shortcut (accelerator) key strokes when a namespace extension's view has the focus. /// The address of the message to be translated. new void TranslateAccelerator(ref MSG lpmsg); + /// Enables or disables modeless dialog boxes. This method is not currently implemented. + /// true to enable modeless dialog box windows or false to disable them. new void EnableModeless([MarshalAs(UnmanagedType.Bool)] bool enable); /// /// Called when the activation state of the view window is changed by an event that is not caused by the Shell view itself. For example, if the TAB @@ -421,7 +530,7 @@ namespace Vanara.PInvoke new void SaveViewState(); /// Changes the selection state of one or more items within the Shell view window. /// The address of the ITEMIDLIST structure. - /// One of the _SVSIF constants that specify the type of selection to apply. + /// One of the _SVSIF constants that specify the type of selection to apply. new void SelectItem(PIDL pidlItem, SVSIF uFlags); /// Gets an interface that refers to data presented in the view. /// The constants that refer to an aspect of the view. @@ -435,7 +544,7 @@ namespace Vanara.PInvoke void GetView([MarshalAs(UnmanagedType.LPStruct)] out Guid pvid, SV2GV uView); /// Used to request the creation of a new Shell view window. It can be either the right pane of Windows Explorer or the client window of a folder window. /// A pointer to an SV2CVW2_PARAMS structure that defines the new view window. - void CreateViewWindow(ref SV2CVW2_PARAMS lpParams); + void CreateViewWindow2(SV2CVW2_PARAMS lpParams); /// Used to change an item's identifier. /// A pointer to an ITEMIDLIST structure. The current identifier is passed in and is replaced by the new one. void HandleRename(PIDL pidlNew); @@ -448,9 +557,12 @@ namespace Vanara.PInvoke /// Extends the capabilities of IShellView2 by providing a method to replace IShellView2::CreateViewWindow2. /// + [PInvokeData("Shobjidl.h")] [ComImport(), Guid("ec39fa88-f8af-41c5-8421-38bed28f4673"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IShellView3 : IShellView2 { + /// Retrieves a handle to one of the windows participating in in-place activation (frame, document, parent, or in-place object window). + /// A pointer to a variable that receives the window handle. new IntPtr GetWindow(); /// Determines whether context-sensitive help mode should be entered during an in-place activation session. /// true if help mode should be entered; false if it should be exited. @@ -458,6 +570,8 @@ namespace Vanara.PInvoke /// Translates keyboard shortcut (accelerator) key strokes when a namespace extension's view has the focus. /// The address of the message to be translated. new void TranslateAccelerator(ref MSG lpmsg); + /// Enables or disables modeless dialog boxes. This method is not currently implemented. + /// true to enable modeless dialog box windows or false to disable them. new void EnableModeless([MarshalAs(UnmanagedType.Bool)] bool enable); /// /// Called when the activation state of the view window is changed by an event that is not caused by the Shell view itself. For example, if the TAB @@ -494,7 +608,7 @@ namespace Vanara.PInvoke new void SaveViewState(); /// Changes the selection state of one or more items within the Shell view window. /// The address of the ITEMIDLIST structure. - /// One of the _SVSIF constants that specify the type of selection to apply. + /// One of the _SVSIF constants that specify the type of selection to apply. new void SelectItem(PIDL pidlItem, SVSIF uFlags); /// Gets an interface that refers to data presented in the view. /// The constants that refer to an aspect of the view. @@ -508,7 +622,7 @@ namespace Vanara.PInvoke new void GetView([MarshalAs(UnmanagedType.LPStruct)] out Guid pvid, SV2GV uView); /// Used to request the creation of a new Shell view window. It can be either the right pane of Windows Explorer or the client window of a folder window. /// A pointer to an SV2CVW2_PARAMS structure that defines the new view window. - new void CreateViewWindow(ref SV2CVW2_PARAMS lpParams); + new void CreateViewWindow2(SV2CVW2_PARAMS lpParams); /// Used to change an item's identifier. /// A pointer to an ITEMIDLIST structure. The current identifier is passed in and is replaced by the new one. new void HandleRename(PIDL pidlNew); @@ -528,10 +642,11 @@ namespace Vanara.PInvoke /// A pointer to a RECT structure that provides the dimensions of the view window. /// A value that receives a pointer to the handle of the new Shell view window. IntPtr CreateViewWindow3(IShellBrowser psbOwner, IShellView psvPrevious, SV3CVW3_FLAGS dwViewFlags, FOLDERFLAGS dwMask, - FOLDERFLAGS dwFlags, FOLDERVIEWMODE fvMode, [MarshalAs(UnmanagedType.LPStruct)] Guid pvid, ref RECT prcView); + FOLDERFLAGS dwFlags, FOLDERVIEWMODE fvMode, [MarshalAs(UnmanagedType.LPStruct)] Guid pvid, PRECT prcView); } /// Contains folder view information. + [PInvokeData("Shobjidl.h")] [StructLayout(LayoutKind.Sequential)] public struct FOLDERSETTINGS { @@ -539,20 +654,90 @@ namespace Vanara.PInvoke public FOLDERVIEWMODE ViewMode; /// A set of flags that indicate the options for the folder. public FOLDERFLAGS fFlags; + + /// Initializes a new instance of the struct. + /// Folder view mode. + /// A set of flags that indicate the options for the folder. + public FOLDERSETTINGS(FOLDERVIEWMODE viewMode, FOLDERFLAGS flags) + { + ViewMode = viewMode; + fFlags = flags; + } } + /// Holds the parameters for the IShellView2::CreateViewWindow2 method. + [PInvokeData("Shobjidl.h")] [StructLayout(LayoutKind.Sequential)] - public struct SV2CVW2_PARAMS + public class SV2CVW2_PARAMS : IDisposable { + /// The size of the structure. public uint cbSize; - public IShellView psvPrev; // IShellView* - public IntPtr pfs; // FOLDERSETTINGS* - public IShellBrowser psbOwner; // IShellBrowser* - public IntPtr prcView; // RECT* - public IntPtr pvid; // GUID* - public IntPtr hwndView; // HWND + /// + /// A pointer to the IShellView interface of the previous view. A Shell view can use this parameter to communicate with a previous view with the same + /// implementation. It can also be used to optimize browsing between like views. This parameter may be NULL. + /// + public IShellView psvPrev; + /// A FOLDERSETTINGS structure with information needed to create the view. + private IntPtr _pfs; + /// + /// A pointer to the current instance of the IShellBrowser interface of the parent Shell browser. IShellView2::CreateViewWindow2 should call this + /// interface's AddRef method and store the interface pointer. It can be used for communication with the Windows Explorer window. + /// + public IShellBrowser psbOwner; + /// A RECT structure that defines the view's display area. + private IntPtr _prcView; + /// + /// A pointer to a view ID. The view ID can be one of the Windows-defined VIDs or a custom, view-defined VID. This value takes precedence over the + /// view mode designated in the FOLDERSETTINGS structure pointed to by pfs. + /// + private IntPtr _pvid; + /// A window handle to the new Shell view. + public IntPtr hwndView; - // TODO: ctor that grabs all but last two fields + /// Initializes a new instance of the class. + /// Folder view mode. + /// A set of flags that indicate the options for the folder. + /// The current instance of the IShellBrowser interface of the parent Shell browser. + /// The view's display area. + /// + /// Optional. The IShellView interface of the previous view. A Shell view can use this parameter to communicate with a previous view with the same + /// implementation. It can also be used to optimize browsing between like views. + /// + public SV2CVW2_PARAMS(FOLDERVIEWMODE viewMode, FOLDERFLAGS flags, IShellBrowser owner, ref RECT displayArea, IShellView prevView = null) + { + cbSize = (uint)Marshal.SizeOf(typeof(SV2CVW2_PARAMS)); + psvPrev = prevView; + psbOwner = owner; + pfs = new FOLDERSETTINGS(viewMode, flags); + prcView = displayArea; + } + + /// A FOLDERSETTINGS structure with information needed to create the view. + public FOLDERSETTINGS pfs + { + get => _pfs.ToStructure(); + set { Marshal.FreeCoTaskMem(_pfs); _pfs = InteropExtensions.StructureToPtr(value, Marshal.AllocCoTaskMem, out var _); } + } + + /// A RECT structure that defines the view's display area. + public RECT prcView + { + get => _prcView.ToStructure(); + set { Marshal.FreeCoTaskMem(_prcView); _prcView = InteropExtensions.StructureToPtr(value, Marshal.AllocCoTaskMem, out var _); } + } + + /// + /// A view ID. The view ID can be one of the Windows-defined VIDs or a custom, view-defined VID. This value takes precedence over the view mode + /// designated in the FOLDERSETTINGS structure pointed to by pfs. + /// + public Guid pvid => _pvid.ToStructure(); + + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + void IDisposable.Dispose() + { + Marshal.FreeCoTaskMem(_pfs); + Marshal.FreeCoTaskMem(_prcView); + } } } } \ No newline at end of file diff --git a/PInvoke/Shell32/ShObjIdl.cs b/PInvoke/Shell32/ShObjIdl.cs index 3e09b172..bf363ec6 100644 --- a/PInvoke/Shell32/ShObjIdl.cs +++ b/PInvoke/Shell32/ShObjIdl.cs @@ -4,8 +4,6 @@ using System.Runtime.InteropServices.ComTypes; using System.Security; using Vanara.Extensions; using Vanara.InteropServices; -using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME; -using static Vanara.PInvoke.Ole32; using static Vanara.PInvoke.PropSys; // ReSharper disable MemberCanBePrivate.Global @@ -64,6 +62,25 @@ namespace Vanara.PInvoke SLGP_RELATIVEPRIORITY = 8 } + /// + /// Used with the IFolderView::Items, IFolderView::ItemCount, and IShellView::GetItemObject methods to restrict or control the items in their collections. + /// + public enum SVGIO : uint + { + /// Refers to the background of the view. It is used with IID_IContextMenu to get a shortcut menu for the view background and with IID_IDispatch to get a dispatch interface that represents the ShellFolderView object for the view. + SVGIO_BACKGROUND = 0, + /// Refers to the currently selected items. Used with IID_IDataObject to retrieve a data object that represents the selected items. + SVGIO_SELECTION = 0x1, + /// Used in the same way as SVGIO_SELECTION but refers to all items in the view. + SVGIO_ALLVIEW = 0x2, + /// Used in the same way as SVGIO_SELECTION but refers to checked items in views where checked mode is supported. For more details on checked mode, see FOLDERFLAGS. + SVGIO_CHECKED = 0x3, + /// Masks all bits but those corresponding to the _SVGIO flags. + SVGIO_TYPE_MASK = 0xf, + /// Returns the items in the order they appear in the view. If this flag is not set, the selected item will be listed first. + SVGIO_FLAG_VIEWORDER = 0x80000000, + } + /// Exposes methods that allow an application to remove one or all destinations from the Recent or Frequent categories in a Jump List. [SuppressUnmanagedCodeSecurity] [ComImport, Guid("12337d35-94c6-48a0-bce7-6a9c69d4d600"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] @@ -154,44 +171,6 @@ namespace Vanara.PInvoke IEnumIDList Clone(); } - /// Exposes enumeration of IShellItem interfaces. This interface is typically obtained by calling the IEnumShellItems method. - [SuppressUnmanagedCodeSecurity] - [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("70629033-e363-4a28-a567-0db78006e6d7")] - [PInvokeData("Shobjidl.h", MSDNShortId = "bb761962")] - public interface IEnumShellItems - { - /// Gets an array of one or more IShellItem interfaces from the enumeration. - /// The number of elements in the array referenced by the rgelt parameter. - /// - /// The address of an array of pointers to IShellItem interfaces that receive the enumerated item or items. The calling application is responsible - /// for freeing the IShellItem interfaces by calling the IUnknown::Release method. - /// - /// - /// A pointer to a value that receives the number of IShellItem interfaces successfully retrieved. The count can be smaller than the value specified - /// in the celt parameter. This parameter can be NULL on entry only if celt is one, because in that case the method can only retrieve one item and - /// return S_OK, or zero items and return S_FALSE. - /// - /// - /// Returns S_OK if the method successfully retrieved the requested celt elements. This method only returns S_OK if the full count of requested items - /// are successfully retrieved. S_FALSE indicates that more items were requested than remained in the enumeration. The value pointed to by the - /// pceltFetched parameter specifies the actual number of items retrieved. Note that the value will be 0 if there are no more items to retrieve. - /// - [PreserveSig] - HRESULT Next(uint celt, [Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Interface, SizeParamIndex = 2)] IShellItem[] rgelt, out uint pceltFetched); - - /// Skips the specified number of elements in the enumeration sequence. - /// The number of IShellItem interfaces to skip. - void Skip(uint celt); - - /// Returns to the beginning of the enumeration sequence. - void Reset(); - - /// Gets a copy of the current enumeration. - /// The address of a pointer that receives a copy of this enumeration. - [return: MarshalAs(UnmanagedType.Interface)] - IEnumShellItems Clone(); - } - /// Exposes methods that enable clients to access items in a collection of objects that support IUnknown. [SuppressUnmanagedCodeSecurity] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("92CA9DCD-5622-4bba-A805-5E9F541BD8C9")] @@ -299,29 +278,6 @@ namespace Vanara.PInvoke uint GetInfoFlags(); } - public enum SVGIO : uint - { - SVGIO_BACKGROUND = 0, - SVGIO_SELECTION = 0x1, - SVGIO_ALLVIEW = 0x2, - SVGIO_CHECKED = 0x3, - SVGIO_TYPE_MASK = 0xf, - SVGIO_FLAG_VIEWORDER = 0x80000000, - } - - /// - /// Indicates the number of menu items in each of the six menu groups of a menu shared between a container and an object server during an in-place editing session. This is the mechanism for building a shared menu. - /// - [StructLayout(LayoutKind.Sequential)] - public struct OLEMENUGROUPWIDTHS - { - /// - /// An array whose elements contain the number of menu items in each of the six menu groups of a shared in-place editing menu. Each menu group can have any number of menu items. The container uses elements 0, 2, and 4 to indicate the number of menu items in its File, View, and Window menu groups. The object server uses elements 1, 3, and 5 to indicate the number of menu items in its Edit, Object, and Help menu groups. - /// - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] public uint[] width; - } - - /// Retrieves the User Model AppID that has been explicitly set for the current process via SetCurrentProcessExplicitAppUserModelID /// The application identifier. ///