using ShellExtensions.Interop.Common; using System; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; namespace ShellExtensions.Interop { internal static class HandlerNativeMethods { #if PREVIEW_HANDLER [DllImport("user32.dll")] internal static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); [DllImport("user32.dll")] internal static extern IntPtr GetFocus(); [DllImport("user32.dll")] internal static extern void SetWindowPos( IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, SetWindowPositionOptions flags); internal static readonly Guid IPreviewHandlerGuid = new Guid("8895b1c6-b41f-4c1c-a562-0d564250836f"); #endif #if THUMBNAIL internal static readonly Guid IThumbnailProviderGuid = new Guid("e357fccd-a995-4576-b01f-234630154e96"); #endif internal static readonly Guid IInitializeWithFileGuid = new Guid("b7d14566-0509-4cce-a71f-0a554233bd9b"); internal static readonly Guid IInitializeWithStreamGuid = new Guid("b824b49d-22ac-4161-ac8a-9916e8fa3f7f"); //internal static readonly Guid IInitializeWithItemGuid = new Guid("7f73be3f-fb79-493c-a6c7-7ee14e245841"); internal static readonly Guid IMarshalGuid = new Guid("00000003-0000-0000-C000-000000000046"); } /// /// Provides means by which to initialize with a file. /// [ComImport] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("b7d14566-0509-4cce-a71f-0a554233bd9b")] interface IInitializeWithFile { /// /// Initializes with a file. /// /// /// void Initialize([MarshalAs(UnmanagedType.LPWStr)] string filePath, AccessModes fileMode); } /// /// Provides means by which to initialize with a stream. /// [ComImport] [Guid("b824b49d-22ac-4161-ac8a-9916e8fa3f7f")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] interface IInitializeWithStream { /// /// Initializes with a stream. /// /// /// void Initialize(IStream stream, AccessModes fileMode); } #if THUMBNAIL #region Interfaces /// /// ComVisible interface for native IThumbnailProvider /// [ComImport] [Guid("e357fccd-a995-4576-b01f-234630154e96")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] interface IThumbnailProvider { /// /// Gets a pointer to a bitmap to display as a thumbnail /// /// /// /// void GetThumbnail(uint squareLength, [Out] out IntPtr bitmapHandle, [Out] out uint bitmapType); } #endregion // /// Thumbnail Alpha Types /// public enum ThumbnailAlphaType { /// /// Let the system decide. /// Unknown = 0, /// /// No transparency /// NoAlphaChannel = 1, /// /// Has transparency /// HasAlphaChannel = 2, } #endif #if PREVIEW_HANDLER [ComImport] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("fc4801a3-2ba9-11cf-a229-00aa003d7352")] interface IObjectWithSite { void SetSite([In, MarshalAs(UnmanagedType.IUnknown)] object pUnkSite); void GetSite(ref Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppvSite); } [ComImport] [Guid("00000114-0000-0000-C000-000000000046")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] interface IOleWindow { void GetWindow(out IntPtr phwnd); void ContextSensitiveHelp([MarshalAs(UnmanagedType.Bool)] bool fEnterMode); } [ComImport] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("8895b1c6-b41f-4c1c-a562-0d564250836f")] interface IPreviewHandler { void SetWindow(IntPtr hwnd, ref NativeRect rect); void SetRect(ref NativeRect rect); void DoPreview(); void Unload(); void SetFocus(); void QueryFocus(out IntPtr phwnd); [PreserveSig] HResult TranslateAccelerator(ref Message pmsg); } [ComImport] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("fec87aaf-35f9-447a-adb7-20234491401a")] interface IPreviewHandlerFrame { void GetWindowContext(IntPtr pinfo); [PreserveSig] HResult TranslateAccelerator(ref Message pmsg); } [ComImport] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("8327b13c-b63f-4b24-9b8a-d010dcc3f599")] interface IPreviewHandlerVisuals { void SetBackgroundColor(NativeColorRef color); void SetFont(ref LogFont plf); void SetTextColor(NativeColorRef color); } #region Structs /// /// Class for marshaling to native LogFont struct /// [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public class LogFont { /// /// Font height /// public int Height { get; set; } /// /// Font width /// public int Width { get; set; } /// /// Font escapement /// public int Escapement { get; set; } /// /// Font orientation /// public int Orientation { get; set; } /// /// Font weight /// public int Weight { get; set; } /// /// Font italic /// public byte Italic { get; set; } /// /// Font underline /// public byte Underline { get; set; } /// /// Font strikeout /// public byte Strikeout { get; set; } /// /// Font character set /// public byte CharacterSet { get; set; } /// /// Font out precision /// public byte OutPrecision { get; set; } /// /// Font clip precision /// public byte ClipPrecision { get; set; } /// /// Font quality /// public byte Quality { get; set; } /// /// Font pitch and family /// public byte PitchAndFamily { get; set; } [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] private string faceName = string.Empty; /// /// Font face name /// public string FaceName { get => faceName; set => faceName = value; } } [StructLayout(LayoutKind.Sequential)] internal struct NativeColorRef { public uint Dword { get; set; } } #endregion [Flags] internal enum SetWindowPositionOptions { AsyncWindowPos = 0x4000, DeferErase = 0x2000, DrawFrame = FrameChanged, FrameChanged = 0x0020, // The frame changed: send WM_NCCALCSIZE HideWindow = 0x0080, NoActivate = 0x0010, CoCopyBits = 0x0100, NoMove = 0x0002, NoOwnerZOrder = 0x0200, // Don't do owner Z ordering NoRedraw = 0x0008, NoResposition = NoOwnerZOrder, NoSendChanging = 0x0400, // Don't send WM_WINDOWPOSCHANGING NoSize = 0x0001, NoZOrder = 0x0004, ShowWindow = 0x0040 } internal enum SetWindowPositionInsertAfter { NoTopMost = -2, TopMost = -1, Top = 0, Bottom = 1 } #endif }