using System; using System.Runtime.InteropServices; namespace Vanara.PInvoke { public static partial class Shell32 { /// The direction that the slideshow should advance. [PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IDesktopWallpaper")] public enum DESKTOP_SLIDESHOW_DIRECTION { /// Advance the slideshow forward. DSD_FORWARD = 0, /// Advance the slideshow backward. DSD_BACKWARD = 1 } /// Options for . [PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IDesktopWallpaper")] [Flags] public enum DESKTOP_SLIDESHOW_OPTIONS { /// Enable shuffle; advance through the slideshow in a random order. DSO_SHUFFLEIMAGES = 0x1 } /// The status of the slideshow. [PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IDesktopWallpaper")] [Flags] public enum DESKTOP_SLIDESHOW_STATE { /// Slideshows are enabled. DSS_ENABLED = 0x1, /// A slideshow is currently configured. DSS_SLIDESHOW = 0x2, /// A remote session has temporarily disabled the slideshow. DSS_DISABLED_BY_REMOTE_SESSION = 0x4 } /// Specifies how the desktop wallpaper should be displayed. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-desktop_wallpaper_position typedef enum // DESKTOP_WALLPAPER_POSITION { DWPOS_CENTER, DWPOS_TILE, DWPOS_STRETCH, DWPOS_FIT, DWPOS_FILL, DWPOS_SPAN } ; [PInvokeData("shobjidl_core.h", MSDNShortId = "NE:shobjidl_core.DESKTOP_WALLPAPER_POSITION")] public enum DESKTOP_WALLPAPER_POSITION { /// Center the image; do not stretch. This is equivalent to the WPSTYLE_CENTER style in IActiveDesktop. DWPOS_CENTER, /// Tile the image across all monitors. This is equivalent to the WPSTYLE_TILE style in IActiveDesktop. DWPOS_TILE, /// Stretch the image to exactly fit on the monitor. This is equivalent to the WPSTYLE_STRETCH style in IActiveDesktop. DWPOS_STRETCH, /// /// Stretch the image to exactly the height or width of the monitor without changing its aspect ratio or cropping the image. /// This can result in colored letterbox bars on either side or on above and below of the image. This is equivalent to the /// WPSTYLE_KEEPASPECT style in IActiveDesktop. /// DWPOS_FIT, /// /// Stretch the image to fill the screen, cropping the image as necessary to avoid letterbox bars. This is equivalent to the /// WPSTYLE_CROPTOFIT style in IActiveDesktop. /// DWPOS_FILL, /// Spans a single image across all monitors attached to the system. This flag has no IActiveDesktop equivalent. DWPOS_SPAN, } /// Provides methods for managing the desktop wallpaper. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-idesktopwallpaper [PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IDesktopWallpaper")] [ComImport, Guid("B92B56A9-8B55-4E14-9A89-0199BBB6F93B"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(DesktopWallpaper))] public interface IDesktopWallpaper { /// Sets the desktop wallpaper. /// /// The ID of the monitor. This value can be obtained through GetMonitorDevicePathAt. Set this value to NULL to set the /// wallpaper image on all monitors. /// /// The full path of the wallpaper image file. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-idesktopwallpaper-setwallpaper HRESULT // SetWallpaper( LPCWSTR monitorID, LPCWSTR wallpaper ); void SetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string monitorID, [MarshalAs(UnmanagedType.LPWStr)] string wallpaper); /// Gets the current desktop wallpaper. /// /// The ID of the monitor. This value can be obtained through GetMonitorDevicePathAt. /// /// This value can be set to NULL. In that case, if a single wallpaper image is displayed on all of the system's /// monitors, the method returns successfully. If this value is set to NULL and different monitors are displaying /// different wallpapers or a slideshow is running, the method returns S_FALSE and an empty string in the wallpaper parameter. /// /// /// /// /// The address of a pointer to a buffer that, when this method returns successfully, receives the path to the wallpaper image /// file. Note that this image could be currently displayed on all of the system's monitors, not just the monitor specified in /// the monitorID parameter. /// /// /// This string will be empty if no wallpaper image is being displayed or if a monitor is displaying a solid color. The string /// will also be empty if the method fails. /// /// /// 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-idesktopwallpaper-getwallpaper HRESULT // GetWallpaper( LPCWSTR monitorID, LPWSTR *wallpaper ); [PreserveSig] HRESULT GetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string monitorID, [MarshalAs(UnmanagedType.LPWStr)] out string wallpaper); /// Retrieves the unique ID of one of the system's monitors. /// The number of the monitor. Call GetMonitorDevicePathCount to determine the total number of monitors. /// /// A pointer to the address of a buffer that, when this method returns successfully, receives the monitor's ID. /// /// /// /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code, including the following. /// /// /// /// Return code /// Description /// /// /// E_POINTER /// A NULL pointer was provided in monitorID. /// /// /// /// /// This method can be called on monitors that are currently detached but that have an image assigned to them. Call /// GetMonitorRECT to distinguish between attached and detached monitors. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-idesktopwallpaper-getmonitordevicepathat // HRESULT GetMonitorDevicePathAt( UINT monitorIndex, LPWSTR *monitorID ); [PreserveSig] HRESULT GetMonitorDevicePathAt(uint monitorIndex, [MarshalAs(UnmanagedType.LPWStr)] out string monitorID); /// Retrieves the number of monitors that are associated with the system. /// A pointer to a value that, when this method returns successfully, receives the number of monitors. /// /// The count retrieved through this method includes monitors that are currently detached but that have an image assigned to /// them. Call GetMonitorRECT to distinguish between attached and detached monitors. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-idesktopwallpaper-getmonitordevicepathcount // HRESULT GetMonitorDevicePathCount( UINT *count ); uint GetMonitorDevicePathCount(); /// Retrieves the display rectangle of the specified monitor. /// The ID of the monitor to query. You can get this value through GetMonitorDevicePathAt. /// /// A pointer to a RECT structure that, when this method returns successfully, receives the display rectangle of the monitor /// specified by monitorID, in screen coordinates. /// /// /// /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code, including the following. /// /// /// /// Return code /// Description /// /// /// S_FALSE /// The monitor specified by monitorID is not currently attached to the system. /// /// /// E_POINTER /// A NULL pointer was provided in displayRect. /// /// /// E_INVALIDARG /// The ID supplied in monitorID cannot be found. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-idesktopwallpaper-getmonitorrect HRESULT // GetMonitorRECT( LPCWSTR monitorID, RECT *displayRect ); [PreserveSig] HRESULT GetMonitorRECT([MarshalAs(UnmanagedType.LPWStr)] string monitorID, out RECT displayRect); /// /// Sets the color that is visible on the desktop when no image is displayed or when the desktop background has been disabled. /// This color is also used as a border when the desktop wallpaper does not fill the entire screen. /// /// A COLORREF value that specifies the background RGB color value. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-idesktopwallpaper-setbackgroundcolor // HRESULT SetBackgroundColor( COLORREF color ); void SetBackgroundColor(COLORREF color); /// /// Retrieves the color that is visible on the desktop when no image is displayed or when the desktop background has been /// disabled. This color is also used as a border when the desktop wallpaper does not fill the entire screen. /// /// /// A pointer to a COLORREF value that, when this method returns successfully, receives the RGB color value. If this method /// fails, this value is set to 0. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-idesktopwallpaper-getbackgroundcolor // HRESULT GetBackgroundColor( COLORREF *color ); COLORREF GetBackgroundColor(); /// /// Sets the display option for the desktop wallpaper image, determining whether the image should be centered, tiled, or stretched. /// /// /// One of the DESKTOP_WALLPAPER_POSITION enumeration values that specify how the image will be displayed on the system's monitors. /// /// /// /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code, including the following. /// /// /// /// Return code /// Description /// /// /// S_FALSE /// The desktop wallpaper is already displayed as asked for in position. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-idesktopwallpaper-setposition HRESULT // SetPosition( DESKTOP_WALLPAPER_POSITION position ); [PreserveSig] HRESULT SetPosition(DESKTOP_WALLPAPER_POSITION position); /// Retrieves the current display value for the desktop background image. /// /// A pointer to a value that, when this method returns successfully, receives one of the DESKTOP_WALLPAPER_POSITION enumeration /// values that specify how the image is being displayed on the system's monitors. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-idesktopwallpaper-getposition HRESULT // GetPosition( DESKTOP_WALLPAPER_POSITION *position ); DESKTOP_WALLPAPER_POSITION GetPosition(); /// Specifies the images to use for the desktop wallpaper slideshow. /// /// A pointer to an IShellItemArray that contains the slideshow images. This array can contain individual items stored in the /// same container (files stored in a folder), or it can contain a single item which is the container itself (a folder that /// contains images). Any other configuration of the array will cause this method to fail. /// /// 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-idesktopwallpaper-setslideshow HRESULT // SetSlideshow( IShellItemArray *items ); void SetSlideshow(IShellItemArray items); /// Gets the images that are being displayed in the desktop wallpaper slideshow. /// /// The address of a pointer to an IShellItemArray object that, when this method returns successfully, receives the items that /// make up the slideshow. This array can contain individual items stored in the same container, or it can contain a single item /// which is the container itself. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-idesktopwallpaper-getslideshow HRESULT // GetSlideshow( IShellItemArray **items ); IShellItemArray GetSlideshow(); /// Sets the desktop wallpaper slideshow settings for shuffle and timing. /// /// Set to either 0 to disable shuffle or the following value. /// DSO_SHUFFLEIMAGES (0x01) /// Enable shuffle; advance through the slideshow in a random order. /// /// The amount of time, in milliseconds, between image transitions. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-idesktopwallpaper-setslideshowoptions // HRESULT SetSlideshowOptions( DESKTOP_SLIDESHOW_OPTIONS options, UINT slideshowTick ); void SetSlideshowOptions(DESKTOP_SLIDESHOW_OPTIONS options, uint slideshowTick); /// Gets the current desktop wallpaper slideshow settings for shuffle and timing. /// /// Type: DESKTOP_SLIDESHOW_OPTIONS* /// /// A pointer to a value that, when this method returns successfully, receives either 0 to indicate that shuffle is disabled or /// the following value. /// /// DSO_SHUFFLEIMAGES (0x01) /// Shuffle is enabled; the images are shown in a random order. /// /// /// Type: UINT* /// /// A pointer to a value that, when this method returns successfully, receives the interval between image transitions, in milliseconds. /// /// /// /// Type: HRESULT /// /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code, including the following. /// /// /// /// Return code /// Description /// /// /// E_POINTER /// A NULL pointer was provided in one of the parameters. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-idesktopwallpaper-getslideshowoptions // HRESULT GetSlideshowOptions( DESKTOP_SLIDESHOW_OPTIONS *options, UINT *slideshowTick ); void GetSlideshowOptions(out DESKTOP_SLIDESHOW_OPTIONS options, out uint slideshowTick); /// Switches the wallpaper on a specified monitor to the next image in the slideshow. /// /// The ID of the monitor on which to change the wallpaper image. This ID can be obtained through the GetMonitorDevicePathAt /// method. If this parameter is set to NULL, the monitor scheduled to change next is used. /// /// /// The direction that the slideshow should advance. One of the following DESKTOP_SLIDESHOW_DIRECTION values: /// DSD_FORWARD (0) /// Advance the slideshow forward. /// DSD_BACKWARD (1) /// Advance the slideshow backward. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-idesktopwallpaper-advanceslideshow HRESULT // AdvanceSlideshow( LPCWSTR monitorID, DESKTOP_SLIDESHOW_DIRECTION direction ); void AdvanceSlideshow([MarshalAs(UnmanagedType.LPWStr)] string monitorID, DESKTOP_SLIDESHOW_DIRECTION direction); /// Gets the current status of the slideshow. /// /// /// A pointer to a DESKTOP_SLIDESHOW_STATE value that, when this method returns successfully, receives one or more of the /// following flags. /// /// DSS_ENABLED (0x01) /// Slideshows are enabled. /// DSS_SLIDESHOW (0x02) /// A slideshow is currently configured. /// DSS_DISABLED_BY_REMOTE_SESSION (0x04) /// A remote session has temporarily disabled the slideshow. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-idesktopwallpaper-getstatus HRESULT // GetStatus( DESKTOP_SLIDESHOW_STATE *state ); DESKTOP_SLIDESHOW_STATE GetStatus(); /// Enables or disables the desktop background. /// TRUE to enable the desktop background, FALSE to disable it. /// /// /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code, including the following. /// /// /// /// Return code /// Description /// /// /// S_FALSE /// The desktop wallpaper is already in the state you're asking for through this call. /// /// /// E_FILE_NOT_FOUND /// /// The desktop wallpaper that would be used when the background is enabled is missing from its expected location. Call /// SetWallpaper to specify a new wallpaper. /// /// /// /// /// /// This method would normally be called to disable the desktop background for performance reasons. /// /// When the desktop background is disabled, a solid color is shown in its place. To get or set the specific color, use the /// GetBackgroundColor and SetBackgroundColor methods. /// /// /// Note A call to the IDesktopWallpaper_SetWallpaper or IDesktopWallpaper_SetSlideshow methods will enable the desktop /// background even if it is currently disabled through this method. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-idesktopwallpaper-enable HRESULT Enable( // BOOL enable ); [PreserveSig] HRESULT Enable([MarshalAs(UnmanagedType.Bool)] bool enable); } /// CLSID_DesktopWallpaper [PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IDesktopWallpaper")] [ComImport, Guid("C2CF3110-460E-4fc1-B9D0-8A1C0C9CC4BD"), ClassInterface(ClassInterfaceType.None)] public class DesktopWallpaper { } } }