using System; using System.Runtime.InteropServices; namespace Vanara.PInvoke { public static partial class Shell32 { /// Alpha channel type information. [PInvokeData("thumbcache.h")] public enum WTS_ALPHATYPE { /// The bitmap is an unknown format. The Shell tries nonetheless to detect whether the image has an alpha channel. WTSAT_UNKNOWN = 0x0, /// The bitmap is an RGB image without alpha. The alpha channel is invalid and the Shell ignores it. WTSAT_RGB = 0x1, /// The bitmap is an ARGB image with a valid alpha channel. WTSAT_ARGB = 0x2 } /// /// /// Exposes a method for getting a thumbnail image and is intended to be implemented for thumbnail handlers. The object that /// implements this interface must also implement IInitializeWithStream. /// /// /// /// The Shell calls IThumbnailProvider::GetThumbnail to obtain an image to use as a representation of the item. /// /// An implementation of this interface for photo thumbnails is supplied in Microsoft Windows as CLSID_PhotoThumbnailProvider. /// Applications that use the supplied implementation must define a constant CLSID identifier using the GUID {C7657C4A-9F68-40fa-A4DF-96BC08EB3551}. /// /// Initializing /// /// The object that implements this interface must also implement IInitializeWithStream . The Shell calls /// IInitializeWithStream::Initialize with the stream of the item, and IInitializeWithStream is the only initialization interface /// used when IThumbnailProvider instances are loaded out-of-proc (for isolation purposes). This is the primary code path for Windows /// for all IThumbnailCache code paths. /// /// /// It is possible for a thumbnail implementation to be initialized with IInitializeWithItem or IInitializeWithFile when the handler /// is request by a 3rd party without using the IThumbnailCache API, but this is uncommon. If you implement /// IInitializeWithItem, the Shell calls IInitializeWithItem::Initialize with the IShellItem representation of the item. If /// you implement IInitializeWithFile, the Shell calls IInitializeWithFile::Initialize with the path of the file. /// /// If none of these interfaces is present, IThumbnailProvider is not called. /// Client apps If you're developing a client app, you should use IShellItemImageFactory instead. /// /// Windows Vista IThumbnailProivder is new for Vista and replaces IExtractImage. Vista still supports IExtractImage but lacks /// the ability to return the image type (alpha or not). /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/thumbcache/nn-thumbcache-ithumbnailprovider [PInvokeData("thumbcache.h", MSDNShortId = "55c4739a-4835-4f53-a435-804ddf06ffcf")] [ComImport, Guid("e357fccd-a995-4576-b01f-234630154e96"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IThumbnailProvider { /// Gets a thumbnail image and alpha type. /// /// The maximum thumbnail size, in pixels. The Shell draws the returned bitmap at this size or smaller. The returned bitmap /// should fit into a square of width and height cx, though it does not need to be a square image. The Shell scales the bitmap to /// render at lower sizes. For example, if the image has a 6:4 aspect ratio, then the returned bitmap should also have a 6:4 /// aspect ratio. /// /// /// When this method returns, contains a pointer to the thumbnail image handle. The image must be a DIB section and 32 bits per /// pixel. The Shell scales down the bitmap if its width or height is larger than the size specified by cx. The Shell always /// respects the aspect ratio and never scales a bitmap larger than its original size. /// /// /// When this method returns, contains a pointer to one of the following values from the WTS_ALPHATYPE enumeration. /// /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. [PreserveSig] HRESULT GetThumbnail(uint cx, out HBITMAP phbmp, out WTS_ALPHATYPE pdwAlpha); } /// An implementation of IThumbnailProvider for photo thumbnails is supplied in Microsoft Windows as CLSID_PhotoThumbnailProvider. [ComImport, Guid("C7657C4A-9F68-40fa-A4DF-96BC08EB3551"), ClassInterface(ClassInterfaceType.None)] [PInvokeData("thumbcache.h")] public class PhotoThumbnailProvider : IThumbnailProvider { /// Gets a thumbnail image and alpha type. /// /// The maximum thumbnail size, in pixels. The Shell draws the returned bitmap at this size or smaller. The returned bitmap /// should fit into a square of width and height cx, though it does not need to be a square image. The Shell scales the bitmap to /// render at lower sizes. For example, if the image has a 6:4 aspect ratio, then the returned bitmap should also have a 6:4 /// aspect ratio. /// /// /// When this method returns, contains a pointer to the thumbnail image handle. The image must be a DIB section and 32 bits per /// pixel. The Shell scales down the bitmap if its width or height is larger than the size specified by cx. The Shell always /// respects the aspect ratio and never scales a bitmap larger than its original size. /// /// /// When this method returns, contains a pointer to one of the following values from the WTS_ALPHATYPE enumeration. /// /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. [PreserveSig] public extern HRESULT GetThumbnail(uint cx, out HBITMAP phbmp, out WTS_ALPHATYPE pdwAlpha); } } }