Exemple #1
0
 public static void InvalidateAttachedPreview(IntPtr handler, Rectangle viewRect)
 {
     if (pHandler != null)
     {
         ShellAPI.RECT r = new ShellAPI.RECT(viewRect);
         pHandler.SetRect(ref r);
     }
 }
 protected override void OnResize(EventArgs e)
 {
     base.OnResize(e);
     if (_previewHandler != null)
     {
         ShellAPI.RECT r = new ShellAPI.RECT(this.ClientRectangle);
         _previewHandler.SetRect(ref r);
     }
 }
Exemple #3
0
        public static void AttachPreview(IntPtr handler, FileInfoEx file, Rectangle viewRect)
        {
            if (pHandler != null)
            {
                pHandler.Unload();
            }
            string fileName = file.FullName;
            string CLSID    = "8895b1c6-b41f-4c1c-a562-0d564250836f";
            Guid   g        = new Guid(CLSID);

            string[] exts = fileName.Split('.');
            string   ext  = exts[exts.Length - 1];

            using (RegistryKey hk = Registry.ClassesRoot.OpenSubKey(string.Format(@".{0}\ShellEx\{1:B}", ext, g)))
            {
                if (hk != null)
                {
                    g = new Guid(hk.GetValue("").ToString());

                    Type   a = Type.GetTypeFromCLSID(g, true);
                    object o = Activator.CreateInstance(a);

                    IInitializeWithFile   fileInit   = o as IInitializeWithFile;
                    IInitializeWithStream streamInit = o as IInitializeWithStream;

                    bool isInitialized = false;
                    if (fileInit != null)
                    {
                        fileInit.Initialize(fileName, 0);
                        isInitialized = true;
                    }
                    else if (streamInit != null)
                    {
                        FileStreamEx stream = file.OpenRead();
                        //COMStream stream = new COMStream(File.Open(fileName, FileMode.Open));
                        streamInit.Initialize((IStream)streamInit, 0);
                        isInitialized = true;
                    }

                    if (isInitialized)
                    {
                        pHandler = o as IPreviewHandler;
                        if (pHandler != null)
                        {
                            ShellAPI.RECT r = new ShellAPI.RECT(viewRect);

                            pHandler.SetWindow(handler, ref r);
                            pHandler.SetRect(ref r);

                            pHandler.DoPreview();
                        }
                    }
                }
            }
        }
        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);
            _previewHandler = PreviewHelper.InitalizePreviewHandler(_file);


            if (_previewHandler != null)
            {
                ShellAPI.RECT r = new ShellAPI.RECT(this.ClientRectangle);
                _previewHandler.SetWindow(this.Handle, ref r);
                _previewHandler.SetRect(ref r);
                _previewHandler.DoPreview();
            }
        }