using System; using System.Runtime.InteropServices; namespace Vanara.PInvoke { public static partial class Shell32 { /// A message id for . [PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IShellMenuCallback")] public enum SMC : uint { /// The callback is called to init a menuband. SMC_INITMENU = 0x00000001, /// The callback is called to init a menuband. SMC_CREATE = 0x00000002, /// The callback is called when menu is collapsing. SMC_EXITMENU = 0x00000003, /// The callback is called to return uint values. SMC_GETINFO = 0x00000005, /// The callback is called to return uint values. SMC_GETSFINFO = 0x00000006, /// The callback is called to get some object. SMC_GETOBJECT = 0x00000007, /// The callback is called to get some object. SMC_GETSFOBJECT = 0x00000008, /// The callback is called to execute an shell folder item. SMC_SFEXEC = 0x00000009, /// The callback is called when an item is selected. SMC_SFSELECTITEM = 0x0000000A, /// Menus have completely refreshed. Reset your state.. SMC_REFRESH = 0x00000010, /// Demote an item. SMC_DEMOTE = 0x00000011, /// Promote an item, wParam = SMINV_* flag. SMC_PROMOTE = 0x00000012, /// Returns Default icon location in wParam, index in lParam. SMC_DEFAULTICON = 0x00000016, /// Notifies item is not in the order stream.. SMC_NEWITEM = 0x00000017, /// Notifies of a expansion via the chevron. SMC_CHEVRONEXPAND = 0x00000019, /// S_OK display, S_FALSE not.. SMC_DISPLAYCHEVRONTIP = 0x0000002A, /// Called to save the passed object. SMC_SETSFOBJECT = 0x0000002D, /// Called when a Change notify is received. lParam points to SMCSHCHANGENOTIFYSTRUCT. SMC_SHCHANGENOTIFY = 0x0000002E, /// Called to get the chevron tip text. wParam = Tip title, Lparam = TipText Both MAX_PATH. SMC_CHEVRONGETTIP = 0x0000002F, /// Called requesting if it's ok to drop. wParam = IDropTarget.. SMC_SFDDRESTRICTED = 0x00000030, /// Same as SFEXEC, but the middle mouse button caused the exec.. SMC_SFEXEC_MIDDLE = 0x00000031, /// callback returns the default autoexpand state lParam = ref uint to recieve flags. SMC_GETAUTOEXPANDSTATE = 0x00000041, /// Notify that the menu is expanding/contracting. SMC_AUTOEXPANDCHANGE = 0x00000042, /// Used to add items to a context menu. SMC_GETCONTEXTMENUMODIFIER = 0x00000043, /// used to get a context menu to display when user right clicks on the background. SMC_GETBKCONTEXTMENU = 0x00000044, /// allows client to overwrite open/explore verb action on an item. SMC_OPEN = 0x00000045, } /// Flags for [PInvokeData("shobjidl_core.h", MSDNShortId = "NS:shobjidl_core.tagSMDATA")] [Flags] public enum SMDM { /// Using the value. SMDM_SHELLFOLDER = 0x00000001, /// Using the value. SMDM_HMENU = 0x00000002, /// SMDM_TOOLBAR = 0x00000004, } /// [PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IShellMenuCallback")] [Flags] public enum SMINFOFLAGS { /// SMIF_ICON = 0x1, /// SMIF_ACCELERATOR = 0x2, /// SMIF_DROPTARGET = 0x4, /// SMIF_SUBMENU = 0x8, /// SMIF_CHECKED = 0x20, /// SMIF_DROPCASCADE = 0x40, /// SMIF_HIDDEN = 0x80, /// SMIF_DISABLED = 0x100, /// SMIF_TRACKPOPUP = 0x200, /// SMIF_DEMOTED = 0x400, /// SMIF_ALTSTATE = 0x800, /// SMIF_DRAGNDROP = 0x1000, /// SMIF_NEW = 0x2000 } /// [PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IShellMenuCallback")] [Flags] public enum SMINFOMASK { /// SMIM_TYPE = 0x1, /// SMIM_FLAGS = 0x2, /// SMIM_ICON = 0x4 } /// [PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IShellMenuCallback")] public enum SMINFOTYPE { /// SMIT_SEPARATOR = 0x1, /// SMIT_STRING = 0x2 } /// Flags that control how the menu operates. [PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IShellMenu")] [Flags] public enum SMINIT { /// No options. SMINIT_DEFAULT = 0x00000000, /// Do not allow drag-and-drop. SMINIT_RESTRICT_DRAGDROP = 0x00000002, /// This is the top band. SMINIT_TOPLEVEL = 0x00000004, /// Do not destroy the band when the window is closed. SMINIT_CACHED = 0x00000010, /// SMINIT_AUTOEXPAND = 0x00000100, /// SMINIT_AUTOTOOLTIP = 0x00000200, /// SMINIT_DROPONCONTAINER = 0x00000400, /// Specifies a vertical band. SMINIT_VERTICAL = 0x10000000, /// Specifies a horizontal band. SMINIT_HORIZONTAL = 0x20000000, } /// Flags that control how the menu is redrawn. [PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IShellMenu")] [Flags] public enum SMINV { /// Use to redraw entire menu. Set psmd to . SMINV_REFRESH = 0x00000001, /// Use when supplying a value to psmd. SMINV_ID = 0x00000008, } /// Flags that specify how the menu operates. [PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IShellMenu")] [Flags] public enum SMSET { /// Attach the menu to the top of the parent menu. SMSET_TOP = 0x10000000, /// Attach the menu to the bottom of the parent menu. SMSET_BOTTOM = 0x20000000, /// /// The menu band does not own the menu named in hwnd, so should that menu eventually be replaced, it should not be destroyed. /// SMSET_DONTOWN = 0x00000001, } /// Exposes methods that interact with Shell menus such as the Start menu, and the Favorites menu. /// /// To get a pointer to this interface, call CoCreateInstance with the rclsid parameter set to CLSID_MenuBand and the riid parameter /// set to IID_IShellMenu. You must first initialize the interface by calling IShellMenu::Initialize, and then initialize the menu /// band by calling IShellMenu::SetShellFolder. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ishellmenu [PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IShellMenu")] [ComImport, Guid("EE1F7637-E138-11d1-8379-00C04FD918D0"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(MenuBand))] public interface IShellMenu { /// Initializes a menu band. /// /// Type: IShellMenuCallback* /// /// A pointer to an IShellMenuCallback interface. This interface receives notifications from the menu. This value can be NULL. /// /// /// /// Type: UINT /// The identifier of the selected menu item. Set this parameter to -1 for the menu itself. /// /// Type: UINT /// /// Type: DWORD /// Flags that control how the menu operates. /// A combination of the following option values: /// /// /// Value /// Meaning /// /// /// SMINIT_DEFAULT /// No options. /// /// /// SMINIT_RESTRICT_DRAGDROP /// Do not allow drag-and-drop. /// /// /// SMINIT_TOPLEVEL /// This is the top band. /// /// /// SMINIT_CACHED /// Do not destroy the band when the window is closed. /// /// /// In addition to the values above, one of the following layout options: /// /// /// Value /// Meaning /// /// /// SMINIT_VERTICAL /// Specifies a vertical band. /// /// /// SMINIT_HORIZONTAL /// Specifies a horizontal band. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellmenu-initialize HRESULT Initialize( // IShellMenuCallback *psmc, UINT uId, UINT uIdAncestor, DWORD dwFlags ); void Initialize([In, Optional] IShellMenuCallback psmc, uint uId, uint uIdAncestor, SMINIT dwFlags); /// Gets information from the IShellMenu::Initialize method. /// /// Type: IShellMenuCallback** /// /// When this method returns, contains the address of a pointer to the IShellMenuCallback interface that you specified when you /// called IShellMenu::Initialize. This pointer can be NULL. /// /// /// /// Type: UINT* /// /// When this method returns, contains a pointer to a UINT value that receives the uID value that you specified when you /// called IShellMenu::Initialize. This pointer can be NULL. /// /// /// /// Type: UINT* /// /// When this method returns, contains a pointer to a UINT value that receives the uIdAncestor value that you specified /// when you called IShellMenu::Initialize. This pointer can be NULL. /// /// /// /// Type: DWORD* /// /// When this method returns, contains a pointer to a DWORD value that receives the dwFlags value that you specified when /// you called IShellMenu::Initialize. This pointer can be NULL. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellmenu-getmenuinfo HRESULT GetMenuInfo( // IShellMenuCallback **ppsmc, UINT *puId, UINT *puIdAncestor, DWORD *pdwFlags ); void GetMenuInfo(out IShellMenuCallback ppsmc, out uint puId, out uint puIdAncestor, out SMINIT pdwFlags); /// Specifies the folder for the menu band to browse. /// /// Type: IShellFolder* /// A pointer to the folder's IShellFolder interface. This pointer can be NULL. /// /// /// Type: PCIDLIST_ABSOLUTE /// The folder's fully qualified ITEMIDLIST. This value can be NULL. /// /// /// Type: HKEY /// An HKEY with an "Order" value that is used to store the order of the menu. This value can be NULL. /// /// /// Type: DWORD /// Flags that specify how the menu band operates. /// SMSET_BOTTOM /// Put this folder at the bottom of the menu. /// SMSET_USEBKICONEXTRACTION /// Use the background icon extractor. /// SMSET_HASEXPANDABLEFOLDERS /// This folder contains expandable folders. /// SMSET_COLLAPSEONEMPTY /// Collapse the menu if empty. /// /// /// Type: HRESULT /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// /// Call this method after you call IShellMenu::Initialize. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellmenu-setshellfolder HRESULT // SetShellFolder( IShellFolder *psf, PCIDLIST_ABSOLUTE pidlFolder, HKEY hKey, DWORD dwFlags ); void SetShellFolder([In, Optional] IShellFolder psf, [In, Optional] PIDL pidlFolder, [In, Optional] HKEY hKey, SMSET dwFlags); /// Gets the folder that the menu band is set to browse. /// /// Type: DWORD* /// When this method returns successfully, contains a pointer to a set of flag values that specify how the menu band operates. /// Can return any of the following flags. /// /// /// Value /// Meaning /// /// /// SMINIT_DEFAULT /// No options. /// /// /// SMINIT_RESTRICT_DRAGDROP /// Do not allow drag-and-drop. /// /// /// SMINIT_TOPLEVEL /// This is the top band. /// /// /// SMINIT_CACHED /// Do not destroy the band when the window is closed. /// /// /// Always returns one of the following flags. /// /// /// Value /// Meaning /// /// /// SMINIT_VERTICAL /// Specifies a vertical band. /// /// /// SMINIT_HORIZONTAL /// Specifies a horizontal band. /// /// /// /// /// Type: PCIDLIST_ABSOLUTE* /// When this method returns, contains the address of the folder's fully qualified ITEMIDLIST. /// /// /// Type: REFIID /// The REFIID for the target folder. /// /// /// Type: void** /// /// When this method returns successfully, contains the address of a pointer to the Shell folder object referenced by the riid. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellmenu-getshellfolder HRESULT // GetShellFolder( DWORD *pdwFlags, PIDLIST_ABSOLUTE *ppidl, REFIID riid, void **ppv ); void GetShellFolder(out SMINIT pdwFlags, out PIDL ppidl, in Guid riid, [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 2)] out object ppv); /// Appends a static menu to the menu band. /// /// Type: HMENU /// The handle of the static menu that is to be appended. This value can be NULL. /// /// /// Type: HWND /// The HWND of the owner window. This value can be NULL. /// /// /// Type: DWORD /// Flags that specify how the menu operates. /// SMSET_BOTTOM /// Attach the menu to the bottom of the parent menu. /// SMSET_TOP /// Attach the menu to the top of the parent menu. /// SMSET_DONTOWN /// The menu band does not own the menu named in hwnd, so should that menu eventually be replaced, it should not be destroyed. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellmenu-setmenu HRESULT SetMenu( HMENU // hmenu, HWND hwnd, DWORD dwFlags ); void SetMenu([In, Optional] HMENU hmenu, [In, Optional] HWND hwnd, SMSET dwFlags); /// Gets the menu information set by calling IShellMenu::SetMenu. /// /// Type: HMENU* /// /// When this method returns, contains a pointer to an HMENU value that receives the hmenu value that you specified when /// you called IShellMenu::SetMenu. This value can be NULL. /// /// /// /// Type: HWND* /// /// When this method returns, contains a pointer to an HWND value that receives the hwnd value that you specified when /// you called IShellMenu::SetMenu. This value can be NULL. /// /// /// /// Type: DWORD* /// /// When this method returns, contains a pointer to a DWORD value that receives the dwFlags value that you specified when /// you called IShellMenu::SetMenu. This value can be NULL. /// /// /// /// Type: HRESULT /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellmenu-getmenu HRESULT GetMenu( HMENU // *phmenu, HWND *phwnd, DWORD *pdwFlags ); void GetMenu(out HMENU phmenu, out HWND phwnd, out SMSET pdwFlags); /// Redraws an item in a menu band. /// /// Type: LPSMDATA /// /// A pointer to an SMDATA structure that identifies the item to be redrawn. Set this value to NULL to redraw the entire menu. /// /// /// /// Type: DWORD /// /// Flags that control how the menu is redrawn. If psmd is NULL, set dwFlags to SMINV_REFRESH. If psmd is set to a valid /// SMDATA structure, set dwFlags to SMINV_ID | SMINV_REFRESH. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellmenu-invalidateitem HRESULT // InvalidateItem( LPSMDATA psmd, DWORD dwFlags ); void InvalidateItem([In, Optional] IntPtr psmd, [In] SMINV dwFlags); /// Gets a filled SMDATA structure. /// /// Type: LPSMDATA /// When this method returns, contains a pointer to an SMDATA structure that contains information about the menu band. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellmenu-getstate HRESULT GetState( // LPSMDATA psmd ); SMDATA GetState(); /// Adds a menu to the menuband. /// /// Type: IUnknown* /// A pointer to an object that supports CLSID_MenuToolbarBase in its QueryInterface method. /// /// /// Type: DWORD /// Flags that control how the menu operates. /// SMSET_TOP /// Bias this namespace to the top of the menu. /// SMSET_BOTTOM /// Bias this namespace to the bottom of the menu. /// SMSET_DONTOWN /// The Menuband does not own the non-ref counted object. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellmenu-setmenutoolbar HRESULT // SetMenuToolbar( IUnknown *punk, DWORD dwFlags ); void SetMenuToolbar([In, MarshalAs(UnmanagedType.IUnknown)] object punk, SMSET dwFlags); } /// A callback interface that exposes a method that receives messages from a menu band. /// /// Once you have created the menu band object, pass a pointer to this interface to the menu band object by calling /// IShellMenu::Initialize. You receive messages from the menu band through the IShellMenuCallback::CallbackSM method. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ishellmenucallback [PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IShellMenuCallback")] [ComImport, Guid("4CA300A1-9B8D-11d1-8B22-00C04FD918D0"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IShellMenuCallback { /// Receives messages from a menu band object. /// /// Type: LPSMDATA /// A pointer to a SMDATA structure that contains information about the menu. /// /// /// Type: UINT /// A message ID. This will be one of the SMC_XXX values. See Shell Messages and Notifications for a complete list. /// /// /// Type: WPARAM /// A WPARAM value that contains additional information. See the specific SMC_XXX message reference for details. /// /// /// Type: LPARAM /// An LPARAM value that contains additional information. See the specific SMC_XXX message reference for details. /// /// /// Type: HRESULT /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellmenucallback-callbacksm HRESULT // CallbackSM( LPSMDATA psmd, UINT uMsg, WPARAM wParam, LPARAM lParam ); [PreserveSig] HRESULT CallbackSM(ref SMDATA psmd, SMC uMsg, [In] IntPtr wParam, [In] IntPtr lParam); } /// Contains information from a menu band. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/ns-shobjidl_core-smdata typedef struct tagSMDATA { DWORD dwMask; // DWORD dwFlags; HMENU hmenu; HWND hwnd; UINT uId; UINT uIdParent; UINT uIdAncestor; IUnknown *punk; PIDLIST_ABSOLUTE pidlFolder; // PUITEMID_CHILD pidlItem; IShellFolder *psf; void *pvUserData; } SMDATA, *LPSMDATA; [PInvokeData("shobjidl_core.h", MSDNShortId = "NS:shobjidl_core.tagSMDATA")] [StructLayout(LayoutKind.Sequential, Pack = 4)] public struct SMDATA { /// /// Type: DWORD /// A mask that is always set to SMDM_HMENU. /// public SMDM dwMask; /// Type: DWORD public uint dwFlags; /// /// Type: HMENU /// The static menu portion of the menu band. /// public HMENU hmenu; /// /// Type: HWND /// The HWND value of the owner window. /// public HWND hwnd; /// /// Type: UINT /// The identifier of the menu item. This value is -1 for the menu itself. /// public uint uId; /// /// Type: UINT /// The identifier of the parent menu. /// public uint uIdParent; /// Type: UINT public uint uIdAncestor; /// /// Type: IUknown* /// A pointer to the IUnknown interface of the MenuBand object. /// public IntPtr punk; /// /// Type: PIDLIST_ABSOLUTE /// The ITEMIDLIST of the shell folder portion of the menu. /// public IntPtr pidlFolder; /// /// Type: PUITEMID_CHILD /// The ITEMIDLIST of the selected item in the shell folder portion of the menu. /// public IntPtr pidlItem; /// /// Type: IShellFolder* /// A pointer to the IShellFolder interface for the folder associated with the shell folder portion of the menu. /// public IntPtr psf; /// /// Type: void* /// A pointer to a user-defined data structure. /// public IntPtr pvUserData; } /// CLSID_MenuBand [ComImport, Guid("5b4dae26-b807-11d0-9815-00c04fd91972"), ClassInterface(ClassInterfaceType.None)] public class MenuBand { } } }