using System;
using System.Drawing;
using System.Runtime.InteropServices;
using static Vanara.PInvoke.OleAut32;
namespace Vanara.PInvoke
{
public static partial class Shell32
{
/// Indicates the current host environment.
[PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IExecuteCommandApplicationHostEnvironment")]
public enum AHE_TYPE
{
/// Desktop.
AHE_DESKTOP = 0,
/// Immersive mode.
AHE_IMMERSIVE = 1
}
/// The UI mode of the host component from which the application was invoked.
[PInvokeData("shobjidl_core.h", MSDNShortId = "NF:shobjidl_core.IExecuteCommandHost.GetUIMode")]
public enum EC_HOST_UI_MODE
{
/// The application is running in the desktop environment.
ECHUIM_DESKTOP = 0,
/// The application is running in the immersive environment.
ECHUIM_IMMERSIVE = (ECHUIM_DESKTOP + 1),
/// The application is running in the system launcher environment.
ECHUIM_SYSTEM_LAUNCHER = (ECHUIM_IMMERSIVE + 1)
}
///
/// Exposes methods that set a given state or parameter related to the command verb, as well as a method to invoke that verb.
///
///
/// When to Implement
///
/// Implement this interface when you choose it as your method to invoke the verb to perform an action on selected items. The items
/// are passed as a Shell item array through IObjectWithSelection::SetSelection, so the object must also implement IObjectWithSelection.
///
/// When to Use
///
/// Do not call the methods of IExecuteCommand directly. Windows Explorer calls your IExecuteCommand methods when the
/// user wants to perform an action on the items.
///
///
/// Note that, apart from Execute, the methods of this interface pass system information to the handler. The system itself calls
/// these methods, setting the parameters appropriately based on system settings and conditions.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nn-shobjidl_core-iexecutecommand
[PInvokeData("shobjidl_core.h", MSDNShortId = "a3432f1a-dd33-4e0d-8b26-1312bb5151f7")]
[ComImport, Guid("7F9185B0-CB92-43c5-80A9-92277A4F7B54"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(ExecuteFolder))]
public interface IExecuteCommand
{
/// Sets a value based on the current state of the keys CTRL and SHIFT.
///
/// Type: DWORD
/// One or both of the following flags to indicate whether the key is pressed.
/// MK_CONTROL
/// The CTRL key is pressed.
/// MK_SHIFT
/// The SHIFT key is pressed.
///
///
/// 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-iexecutecommand-setkeystate HRESULT
// SetKeyState( DWORD grfKeyState );
[PreserveSig]
HRESULT SetKeyState(MouseButtonState grfKeyState);
/// Provides parameter values for the verb.
///
/// Type: LPCWSTR
///
/// Pointer to a string that contains parameter values. The format and contents of this string is determined by the verb that is
/// to be invoked.
///
///
///
/// 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-iexecutecommand-setparameters HRESULT
// SetParameters( LPCWSTR pszParameters );
[PreserveSig]
HRESULT SetParameters([In, MarshalAs(UnmanagedType.LPWStr)] string pszParameters);
/// Sets the coordinates of a point used for display.
///
/// Type: POINT
///
/// The screen coordinates at which the user right-clicked to invoke the shortcut menu from which a command was chosen.
/// Applications can use this information to present any UI. This is particularly useful in a multi-monitor situation. The
/// default position is the center of the default monitor.
///
///
///
/// 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-iexecutecommand-setposition HRESULT
// SetPosition( POINT pt );
[PreserveSig]
HRESULT SetPosition(Point pt);
/// Sets the specified window's visual state.
///
/// Type: int
/// One of the following flags to indicate how the window is to be shown.
/// SW_HIDE
/// Hides the window and activates another window.
/// SW_MAXIMIZE
/// Maximizes the specified window.
/// SW_MINIMIZE
/// Minimizes the specified window and activates the next top-level window in the z-order.
/// SW_RESTORE
///
/// Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and
/// position. An application should specify this flag when restoring a minimized window.
///
/// SW_SHOW
/// Activates the window and displays it in its current size and position.
/// SW_SHOWDEFAULT
///
/// Sets the show state based on the information specified in the STARTUPINFO structure passed to the CreateProcess function
/// that started the application. An application should call ShowWindow with this flag to set the initial visual state of its
/// main window.
///
/// SW_SHOWMAXIMIZED
/// Activates the window and displays it as a maximized window.
/// SW_SHOWMINIMIZED
/// Activates the window and displays it as a minimized window.
/// SW_SHOWMINNOACTIVE
/// Displays the window as a minimized window. The active window remains active.
/// SW_SHOWNA
/// Displays the window in its current state. The active window remains active.
/// SW_SHOWNOACTIVATE
/// Displays a window in its most recent size and position. The active window remains active.
/// SW_SHOWNORMAL
///
/// Default state. Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original
/// size and position. An application should specify this flag when it displays the window for the first time.
///
///
///
/// 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-iexecutecommand-setshowwindow HRESULT
// SetShowWindow( int nShow );
[PreserveSig]
HRESULT SetShowWindow(ShowWindowCommand nShow);
/// Indicates whether any UI associated with the selected Shell item should be displayed.
///
/// Type: BOOL
/// TRUE to block display of any associated UI; FALSE to display the UI. FALSE is the default value.
///
///
/// 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-iexecutecommand-setnoshowui HRESULT
// SetNoShowUI( BOOL fNoShowUI );
[PreserveSig]
HRESULT SetNoShowUI([MarshalAs(UnmanagedType.Bool)] bool fNoShowUI);
/// Sets a new working directory.
///
/// Type: LPCWSTR
///
/// Pointer to a null-terminated string with the fully qualified path of the new working directory. If this value is
/// NULL, the current working directory is used.
///
///
///
/// 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-iexecutecommand-setdirectory HRESULT
// SetDirectory( LPCWSTR pszDirectory );
[PreserveSig]
HRESULT SetDirectory([In, MarshalAs(UnmanagedType.LPWStr)] string pszDirectory);
/// Invoke the verb on the selected items. Call this method after you have called the other methods of this interface.
///
/// 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-iexecutecommand-execute HRESULT Execute( );
[PreserveSig]
HRESULT Execute();
}
///
/// Provides a method that enables an IExplorerCommand-based Shell verb handler to query the UI mode of the host component from
/// which the application was invoked.
///
///
/// When to implement
///
/// A software component (either an OS component or an application) taat can launch a dual-mode application such as a browser should
/// implement this interface. The interface should be implemented on an object that can be reached through the site chain provided
/// to ShellExecuteEx or the context menu and retrieved through the IServiceProvider::QueryService method.
///
/// When to use
///
/// Typically, an application that is capable of launching as both a desktop application and a Windows Store app app will use this
/// interface to query which mode the host is currently in. The application can then launch in the UI mode that is compatible with
/// the host.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-iexecutecommandhost
[ComImport, Guid("4b6832a2-5f04-4c9d-b89d-727a15d103e7"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IExecuteCommandHost
{
///
/// Enables an IExplorerCommand-based Shell verb handler to query the UI mode of the host component from which the application
/// was invoked.
///
///
/// Type: EC_HOST_UI_MODE*
/// ECHUIM_DESKTOP (0)
/// The application is running in the desktop environment.
/// ECHUIM_IMMERSIVE (1)
/// The application is running in the immersive environment.
/// ECHUIM_SYSTEM_LAUNCHER (2)
/// The application is running in the system launcher environment.
///
/// 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-iexecutecommandhost-getuimode HRESULT
// GetUIMode( EC_HOST_UI_MODE *pUIMode );
[PreserveSig]
HRESULT GetUIMode(out EC_HOST_UI_MODE pUIMode);
}
/// Provides a single method that enables an application to determine whether its host is in desktop or immersive mode.
///
/// When to implement
/// An application must implement this interface together with the DelegateExecute handler (IExecuteCommand).
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-iexecutecommandapplicationhostenvironment
[PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IExecuteCommandApplicationHostEnvironment")]
[ComImport, Guid("18B21AA9-E184-4FF0-9F5E-F882D03771B3"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IExecuteCommandApplicationHostEnvironment
{
/// Determines whether the current application host environment is in the desktop or immersive mode.
///
///
/// A pointer to a AHE_TYPE value that, when this method returns successfully, receives one of the following values to
/// indicate the current host environment.
///
/// AHE_DESKTOP (0)
/// Desktop.
/// AHE_IMMERSIVE (1)
/// Immersive mode.
///
/// 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-iexecutecommandapplicationhostenvironment-getvalue
// HRESULT GetValue( AHE_TYPE *pahe );
[PreserveSig]
HRESULT GetValue(out AHE_TYPE pahe);
}
///
/// Exposes a single method used to initialize objects that implement IExplorerCommandState, IExecuteCommand or IDropTarget with the
/// application-specified command name and its registered properties.
///
///
/// When to Implement
/// Implement IInitializeCommand in the following situations.
///
/// -
///
/// Implement this interface to differentiate between related commands that share implementations of IExplorerCommandState,
/// IDropTarget or IExecuteCommand. Differentiation is made through the command name passed in IInitializeCommand::Initialize.
/// Commands can also use Initialize to pass a specific property bag for the command, using properties the command has placed
/// in the registry.
///
///
///
/// When to Use
///
/// Do not call the method of IInitializeCommand directly. Windows Explorer calls this method when a verb object that
/// implements this interface is invoked.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nn-shobjidl_core-iinitializecommand
[PInvokeData("shobjidl_core.h", MSDNShortId = "e5a2a4d3-2488-4da2-aaab-c27461859d9f")]
[ComImport, Guid("85075acf-231f-40ea-9610-d26b7b58f638"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInitializeCommand
{
///
/// Initialize objects that share an implementation of IExplorerCommandState, IExecuteCommand or IDropTarget with the
/// application-specified command name and its registered properties.
///
///
/// Type: LPCWSTR
///
/// Pointer to a string that contains the command name (the name of the command key as found in the registry). For instance, if
/// the command is registered under ...<b>shell<b>MyCommand, pszCommandName points to "MyCommand".
///
///
///
/// Type: IPropertyBag*
///
/// Pointer to an IPropertyBag instance that can be used to read the properties related to the command in the registry. For
/// example, a command may registry a string property under its ...<b>shell<b>MyCommand subkey.
///
///
///
/// 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-iinitializecommand-initialize HRESULT
// Initialize( LPCWSTR pszCommandName, IPropertyBag *ppb );
[PreserveSig]
HRESULT Initialize([In, MarshalAs(UnmanagedType.LPWStr)] string pszCommandName, [In] IPropertyBag ppb);
}
/// CLSID_AppShellVerbHandler
[PInvokeData("shobjidl.h")]
[ComImport, Guid("4ED3A719-CEA8-4BD9-910D-E252F997AFC2"), ClassInterface(ClassInterfaceType.None)]
public class AppShellVerbHandler { }
/// CoClass for IExecuteCommand
[PInvokeData("shobjidl.h")]
[ComImport, Guid("11dbb47c-a525-400b-9e80-a54615a090c0"), ClassInterface(ClassInterfaceType.None)]
public class ExecuteFolder { }
/// CLSID_ExecuteUnknown
[PInvokeData("shobjidl.h")]
[ComImport, Guid("e44e9428-bdbc-4987-a099-40dc8fd255e7"), ClassInterface(ClassInterfaceType.None)]
public class ExecuteUnknown { }
}
}