From d64d154c08decce68d60e6529cfd8cab3560ed2d Mon Sep 17 00:00:00 2001 From: David Hall Date: Sun, 22 Jul 2018 14:37:06 -0600 Subject: [PATCH] Added IOleCommandTarget, IInputObject and IStartMenuPinnedList interfaces and supporting code --- PInvoke/Shell32/DocObj.IOleCommandTarget.cs | 265 +++++++++++++++++++++++ PInvoke/Shell32/ShObjIdl.IInputObject.cs | 88 ++++++++ PInvoke/Shell32/ShObjIdl.IStartMenuPinnedList.cs | 34 +++ 3 files changed, 387 insertions(+) create mode 100644 PInvoke/Shell32/DocObj.IOleCommandTarget.cs create mode 100644 PInvoke/Shell32/ShObjIdl.IInputObject.cs create mode 100644 PInvoke/Shell32/ShObjIdl.IStartMenuPinnedList.cs diff --git a/PInvoke/Shell32/DocObj.IOleCommandTarget.cs b/PInvoke/Shell32/DocObj.IOleCommandTarget.cs new file mode 100644 index 00000000..984cf0dc --- /dev/null +++ b/PInvoke/Shell32/DocObj.IOleCommandTarget.cs @@ -0,0 +1,265 @@ +using System; +using System.Runtime.InteropServices; + +namespace Vanara.PInvoke +{ + public static partial class Shell32 + { + /// Specifies command execution options. + [PInvokeData("docobj.h")] + public enum OLECMDEXECOPT + { + /// Prompt the user for input or not, whichever is the default behavior. + OLECMDEXECOPT_DODEFAULT = 0, + /// Execute the command after obtaining user input. + OLECMDEXECOPT_PROMPTUSER = 1, + /// + /// Execute the command without prompting the user. For example, clicking the Print toolbar button causes a document to be + /// immediately printed without user input. + /// + OLECMDEXECOPT_DONTPROMPTUSER = 2, + /// Show help for the corresponding command, but do not execute. + OLECMDEXECOPT_SHOWHELP = 3 + } + + /// Specifies the type of support provided by an object for the command specified in an OLECMD structure. + [PInvokeData("docobj.h")] + public enum OLECMDF + { + /// The command is supported by this object. + OLECMDF_SUPPORTED = 0x00000001, + /// The command is available and enabled. + OLECMDF_ENABLED = 0x00000002, + /// The command is an on-off toggle and is currently on. + OLECMDF_LATCHED = 0x00000004, + /// Reserved for future use. + OLECMDF_NINCHED = 0x00000008, + /// The command is hidden. + OLECMDF_INVISIBLE = 0x00000010, + /// The command is hidden on the context menu. + OLECMDF_DEFHIDEONCTXTMENU = 0x00000020, + } + + public enum OLECMDID + { + OLECMDID_OPEN = 1, + OLECMDID_NEW = 2, + OLECMDID_SAVE = 3, + OLECMDID_SAVEAS = 4, + OLECMDID_SAVECOPYAS = 5, + OLECMDID_PRINT = 6, + OLECMDID_PRINTPREVIEW = 7, + OLECMDID_PAGESETUP = 8, + OLECMDID_SPELL = 9, + OLECMDID_PROPERTIES = 10, + OLECMDID_CUT = 11, + OLECMDID_COPY = 12, + OLECMDID_PASTE = 13, + OLECMDID_PASTESPECIAL = 14, + OLECMDID_UNDO = 15, + OLECMDID_REDO = 16, + OLECMDID_SELECTALL = 17, + OLECMDID_CLEARSELECTION = 18, + OLECMDID_ZOOM = 19, + OLECMDID_GETZOOMRANGE = 20, + OLECMDID_UPDATECOMMANDS = 21, + OLECMDID_REFRESH = 22, + OLECMDID_STOP = 23, + OLECMDID_HIDETOOLBARS = 24, + OLECMDID_SETPROGRESSMAX = 25, + OLECMDID_SETPROGRESSPOS = 26, + OLECMDID_SETPROGRESSTEXT = 27, + OLECMDID_SETTITLE = 28, + OLECMDID_SETDOWNLOADSTATE = 29, + OLECMDID_STOPDOWNLOAD = 30, + OLECMDID_ONTOOLBARACTIVATED = 31, + OLECMDID_FIND = 32, + OLECMDID_DELETE = 33, + OLECMDID_HTTPEQUIV = 34, + OLECMDID_HTTPEQUIV_DONE = 35, + OLECMDID_ENABLE_INTERACTION = 36, + OLECMDID_ONUNLOAD = 37, + OLECMDID_PROPERTYBAG2 = 38, + OLECMDID_PREREFRESH = 39, + OLECMDID_SHOWSCRIPTERROR = 40, + OLECMDID_SHOWMESSAGE = 41, + OLECMDID_SHOWFIND = 42, + OLECMDID_SHOWPAGESETUP = 43, + OLECMDID_SHOWPRINT = 44, + OLECMDID_CLOSE = 45, + OLECMDID_ALLOWUILESSSAVEAS = 46, + OLECMDID_DONTDOWNLOADCSS = 47, + OLECMDID_UPDATEPAGESTATUS = 48, + OLECMDID_PRINT2 = 49, + OLECMDID_PRINTPREVIEW2 = 50, + OLECMDID_SETPRINTTEMPLATE = 51, + OLECMDID_GETPRINTTEMPLATE = 52, + OLECMDID_PAGEACTIONBLOCKED = 55, + OLECMDID_PAGEACTIONUIQUERY = 56, + OLECMDID_FOCUSVIEWCONTROLS = 57, + OLECMDID_FOCUSVIEWCONTROLSQUERY = 58, + OLECMDID_SHOWPAGEACTIONMENU = 59, + OLECMDID_ADDTRAVELENTRY = 60, + OLECMDID_UPDATETRAVELENTRY = 61, + OLECMDID_UPDATEBACKFORWARDSTATE = 62, + OLECMDID_OPTICAL_ZOOM = 63, + OLECMDID_OPTICAL_GETZOOMRANGE = 64, + OLECMDID_WINDOWSTATECHANGED = 65, + OLECMDID_ACTIVEXINSTALLSCOPE = 66, + OLECMDID_UPDATETRAVELENTRY_DATARECOVERY = 67, + OLECMDID_SHOWTASKDLG = 68, + OLECMDID_POPSTATEEVENT = 69, + OLECMDID_VIEWPORT_MODE = 70, + OLECMDID_LAYOUT_VIEWPORT_WIDTH = 71, + OLECMDID_VISUAL_VIEWPORT_EXCLUDE_BOTTOM = 72, + OLECMDID_USER_OPTICAL_ZOOM = 73, + OLECMDID_PAGEAVAILABLE = 74, + OLECMDID_GETUSERSCALABLE = 75, + OLECMDID_UPDATE_CARET = 76, + OLECMDID_ENABLE_VISIBILITY = 77, + OLECMDID_MEDIA_PLAYBACK = 78, + OLECMDID_SETFAVICON = 79, + OLECMDID_SET_HOST_FULLSCREENMODE = 80, + OLECMDID_EXITFULLSCREEN = 81, + OLECMDID_SCROLLCOMPLETE = 82, + OLECMDID_ONBEFOREUNLOAD = 83, + OLECMDID_SHOWMESSAGE_BLOCKABLE = 84, + OLECMDID_SHOWTASKDLG_BLOCKABLE = 85, + } + + /// Specifies the window state. + [PInvokeData("docobj.h")] + [Flags] + public enum OLECMDID_WINDOWSTATE_FLAG + { + /// The window is visible. + OLECMDIDF_WINDOWSTATE_USERVISIBLE = 0x01, + /// The window has focus. + OLECMDIDF_WINDOWSTATE_ENABLED = 0x02, + /// The window is visible and valid. + OLECMDIDF_WINDOWSTATE_USERVISIBLE_VALID = 0x00010000, + /// The window has focus and is valid. + OLECMDIDF_WINDOWSTATE_ENABLED_VALID = 0x00020000 + } + + /// + /// Specifies the type of information that an object should store in the OLECMDTEXT structure passed in + /// IOleCommandTarget::QueryStatus. One value from this enumeration is stored the cmdtextf member of the OLECMDTEXT structure to + /// indicate the desired information. + /// + [PInvokeData("docobj.h")] + public enum OLECMDTEXTF + { + /// No extra information is requested. + OLECMDTEXTF_NONE = 0, + /// The object should provide the localized name of the command. + OLECMDTEXTF_NAME = 1, + /// The object should provide a localized status string for the command. + OLECMDTEXTF_STATUS = 2, + } + + /// + /// Enables objects and their containers to dispatch commands to each other. For example, an object's toolbars may contain buttons + /// for commands such as Print, Print Preview, Save, New, and Zoom. + /// + /// Normal in-place activation guidelines recommend that you remove or disable such buttons because no efficient, standard mechanism + /// has been available to dispatch them to the container.Similarly, a container has heretofore had no efficient means to send + /// commands such as Print, Page Setup, and Properties to an in-place active object. Such simple command routing could have been + /// handled through existing OLE Automation standards and the IDispatch interface, but the overhead with IDispatch is more than is + /// required in the case of document objects.The IOleCommandTarget interface provides a simpler means to achieve the same ends. + /// + /// + /// Available commands are defined by integer identifiers in a group. The group itself is identified with a GUID. The interface + /// allows a caller both to query for support of one or more commands within a group and to issue a supported command to the object. + /// + /// + [ComImport, Guid("B722BCCB-4E68-101B-A2BC-00AA00404770"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [PInvokeData("docobj.h")] + public interface IOleCommandTarget + { + /// Queries the object for the status of one or more commands generated by user interface events. + /// + /// The unique identifier of the command group; can be NULL to specify the standard group. All the commands that are passed in + /// the prgCmds array must belong to the group specified by pguidCmdGroup. + /// + /// The number of commands in the prgCmds array. + /// + /// A caller-allocated array of OLECMD structures that indicate the commands for which the caller needs status information. This + /// method fills the cmdf member of each structure with values taken from the OLECMDF enumeration. + /// + /// + /// A pointer to an OLECMDTEXT structure in which to return name and/or status information of a single command. This parameter + /// can be NULL to indicate that the caller does not need this information. + /// + /// This method returns S_OK on success. + [PreserveSig] + HRESULT QueryStatus([In, MarshalAs(UnmanagedType.LPStruct)] Guid pguidCmdGroup, uint cCmds, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] OLECMD[] prgCmds, OLECMDTEXT pCmdText); + + /// Executes the specified command or displays help for the command. + /// The unique identifier of the command group; can be NULL to specify the standard group. + /// The command to be executed. This command must belong to the group specified with pguidCmdGroup. + /// + /// Specifies how the object should execute the command. Possible values are taken from the OLECMDEXECOPT and + /// OLECMDID_WINDOWSTATE_FLAG enumerations. + /// + /// A pointer to a VARIANTARG structure containing input arguments. This parameter can be NULL. + /// Pointer to a VARIANTARG structure to receive command output. This parameter can be NULL. + /// This method returns S_OK on success. + [PreserveSig] + HRESULT Exec([In, MarshalAs(UnmanagedType.LPStruct)] Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, [In, MarshalAs(UnmanagedType.LPArray)] object[] pvaIn, IntPtr pvaOut); + } + + /// Associates command flags from the OLECMDF enumeration with a command identifier through a call to IOleCommandTarget::QueryStatus. + [PInvokeData("docobj.h")] + [StructLayout(LayoutKind.Sequential)] + public struct OLECMD + { + /// A command identifier; taken from the OLECMDID enumeration. + public OLECMDID cmdID; + + /// Flags associated with cmdID; taken from the OLECMDF enumeration. + public OLECMDF cmdf; + } + + /// Specifies a text name or status string for a single command identifier. + [StructLayout(LayoutKind.Sequential)] + public class OLECMDTEXT : IDisposable + { + /// + /// A value from the OLECMDTEXTF enumeration describing whether the rgwz member contains a command name or status text. + /// + public OLECMDTEXTF cmdtextf; + + /// The number of characters actually written into the rgwz buffer before IOleCommandTarget::QueryStatus returns. + public uint cwActual; + + /// The number of elements in the rgwz array. + public uint cwBuf; + + private InteropServices.StrPtrUni _rgwz; + + public OLECMDTEXT(OLECMDTEXTF cmdtextf, string nameOrStatus) + { + this.cmdtextf = cmdtextf; + if (nameOrStatus != null) + rgwz = nameOrStatus; + } + + /// The command name or status text. + public string rgwz + { + get => _rgwz; + set { if (value == null) _rgwz.Free(); else _rgwz.Assign(value, out cwActual); } + } + + /// Returns a that represents this instance. + /// A that represents this instance. + public override string ToString() => rgwz; + + void IDisposable.Dispose() + { + _rgwz.Free(); + } + } + } +} \ No newline at end of file diff --git a/PInvoke/Shell32/ShObjIdl.IInputObject.cs b/PInvoke/Shell32/ShObjIdl.IInputObject.cs new file mode 100644 index 00000000..11e13287 --- /dev/null +++ b/PInvoke/Shell32/ShObjIdl.IInputObject.cs @@ -0,0 +1,88 @@ +using System; +using System.Runtime.InteropServices; + +namespace Vanara.PInvoke +{ + public static partial class Shell32 + { + /// Exposes methods that change UI activation and process accelerators for a user input object contained in the Shell. + [ComImport, Guid("68284fAA-6A48-11D0-8c78-00C04fd918b4"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [PInvokeData("ShObjIdl_core.h")] + public interface IInputObject + { + /// UI-activates or deactivates the object. + /// + /// Indicates if the object is being activated or deactivated. If this value is nonzero, the object is being activated. If this + /// value is zero, the object is being deactivated. + /// + /// + /// A pointer to an MSG structure that contains the message that caused the activation change. This value may be NULL. + /// + /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + [PreserveSig] + HRESULT UIActivateIO([In, MarshalAs(UnmanagedType.Bool)] bool fActivate, [In, MarshalAs(UnmanagedType.LPStruct)] MSG pMsg); + + /// Determines if one of the object's windows has the keyboard focus. + /// Returns S_OK if one of the object's windows has the keyboard focus, or S_FALSE otherwise. + [PreserveSig] + HRESULT HasFocusIO(); + + /// Enables the object to process keyboard accelerators. + /// The address of an MSG structure that contains the keyboard message that is being translated. + /// Returns S_OK if the accelerator was translated, or S_FALSE otherwise. + [PreserveSig] + HRESULT TranslateAcceleratorIO([In, MarshalAs(UnmanagedType.LPStruct)] MSG pMsg); + } + + /// Exposes a method that extends IInputObject by handling global accelerators. + [ComImport, Guid("6915C085-510B-44cd-94AF-28DFA56CF92B"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [PInvokeData("ShObjIdl_core.h")] + public interface IInputObject2 : IInputObject + { + /// UI-activates or deactivates the object. + /// + /// Indicates if the object is being activated or deactivated. If this value is nonzero, the object is being activated. If this + /// value is zero, the object is being deactivated. + /// + /// + /// A pointer to an MSG structure that contains the message that caused the activation change. This value may be NULL. + /// + /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + [PreserveSig] + new HRESULT UIActivateIO([In, MarshalAs(UnmanagedType.Bool)] bool fActivate, [In, MarshalAs(UnmanagedType.LPStruct)] MSG pMsg); + + /// Determines if one of the object's windows has the keyboard focus. + /// Returns S_OK if one of the object's windows has the keyboard focus, or S_FALSE otherwise. + [PreserveSig] + new HRESULT HasFocusIO(); + + /// Enables the object to process keyboard accelerators. + /// The address of an MSG structure that contains the keyboard message that is being translated. + /// Returns S_OK if the accelerator was translated, or S_FALSE otherwise. + [PreserveSig] + new HRESULT TranslateAcceleratorIO([In, MarshalAs(UnmanagedType.LPStruct)] MSG pMsg); + + /// + /// Handles global accelerators so that input objects can respond to the keyboard even when they are not active in the UI. + /// + /// A pointer to an MSG structure that contains a keyboard message. + /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + [PreserveSig] + HRESULT TranslateAcceleratorGlobal([In, MarshalAs(UnmanagedType.LPStruct)] MSG pMsg); + } + + /// Exposes a method that is used to communicate focus changes for a user input object contained in the Shell. + [ComImport, Guid("F1DB8392-7331-11D0-8C99-00A0C92DBFE8"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [PInvokeData("ShObjIdl_core.h")] + public interface IInputObjectSite + { + /// Informs the browser that the focus has changed. + /// The address of the IUnknown interface of the object gaining or losing the focus. + /// + /// Indicates if the object has gained or lost the focus. If this value is nonzero, the object has gained the focus. If this + /// value is zero, the object has lost the focus. + /// + void OnFocusChangeIS([In, MarshalAs(UnmanagedType.IUnknown)] object punkObj, [In, MarshalAs(UnmanagedType.Bool)] bool fSetFocus); + } + } +} \ No newline at end of file diff --git a/PInvoke/Shell32/ShObjIdl.IStartMenuPinnedList.cs b/PInvoke/Shell32/ShObjIdl.IStartMenuPinnedList.cs new file mode 100644 index 00000000..59b865cf --- /dev/null +++ b/PInvoke/Shell32/ShObjIdl.IStartMenuPinnedList.cs @@ -0,0 +1,34 @@ +using System; +using System.Runtime.InteropServices; + +namespace Vanara.PInvoke +{ + public static partial class Shell32 + { + /// Exposes a method that unpins an application shortcut from the Start menu or the taskbar. + [ComImport, Guid("4CD19ADA-25A5-4A32-B3B7-347BEE5BE36B"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(StartMenuPin))] + [PInvokeData("shobjidl.h")] + public interface IStartMenuPinnedList + { + /// + /// Windows Vista: Removes an item from the Start menu pinned list, which is the list in the upper left position of the Start menu. + /// Windows 7: Removes an item from the Start menu pinned list and unpins the item from the taskbar. + /// Windows 8: Unpins the item from the taskbar but does not remove the item from the Start screen. Items cannot be programmatically removed from Start; they can only be unpinned by the user or removed as part of a program's uninstallation. + /// A pointer to an IShellItem object that represents the item to unpin. + /// + /// + /// Returns S_OK if the item was successfully removed from the list of pinned items and/or the taskbar. + /// Returns S_OK if the item was not pinned at all. + /// Returns a standard error code otherwise. + /// + /// + [PreserveSig] + HRESULT RemoveFromList([In] IShellItem pitem); + } + + /// CoClass for IStartMenuPinnedList (CLSID_StartMenuPin). + [PInvokeData("shobjidl.h")] + [ComImport, Guid("a2a9545d-a0c2-42b4-9708-a0b2badd77c8"), ClassInterface(ClassInterfaceType.None)] + public class StartMenuPin { } + } +} \ No newline at end of file