C#实现Windows资源管理器文件预览

上一篇文章大致介绍了一下C++实现Windows文件预览的方法,这里介绍一下通过.NET方式实现文件预览。

其实原理还是一样,需要通过实现系统定义的COM接口,包括

IInitializeWithFile,IObjectWithSite, IOleWindow,IPreviewHandler

等而C#并没有定义这些接口,因此我们需要把这些接口通过System.Runtime.InteropServices先从COM中引进到项目中

 [ComImport]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    [Guid("8895b1c6-b41f-4c1c-a562-0d564250836f")]
      public interface IPreviewHandler
    {
        /// 
        /// Sets the parent window of the previewer window, as well as the area within the parent to be used for the previewer window.
        /// 
        /// A handle to the parent window.
        /// A pointer to a RECT defining the area for the previewer.
        /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT erro

你可能感兴趣的:(.net,windows,sharpshell,COM,c#)