Ejemplo n.º 1
0
        public static IPreviewHandler InitalizePreviewHandler(FileInfoEx file)
        {
            IPreviewHandler retVal    = null;
            PreviewerInfo   previewer = getPreviewer(file.FullName);

            if (previewer != null)
            {
                bool   isInitialized = false;
                Type   a             = Type.GetTypeFromCLSID(previewer.CLSID, true);
                object o             = Activator.CreateInstance(a);

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

                if (fileInit != null)
                {
                    fileInit.Initialize(file.FullName, 0);
                    isInitialized = true;
                }
                else if (streamInit != null)
                {
                    FileStreamEx stream = file.OpenRead();
                    streamInit.Initialize((IStream)stream, 0);
                    isInitialized = true;
                }

                if (isInitialized)
                {
                    retVal = o as IPreviewHandler;
                }
            }
            return(retVal);
        }
Ejemplo n.º 2
0
        public void AttachPreview(IntPtr handler, string fileName, Rect viewRect)
        {
            Release();

            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   type   = Type.GetTypeFromCLSID(g, true);
                    object comObj = Activator.CreateInstance(type);

                    IInitializeWithFile   fileInit   = comObj as IInitializeWithFile;
                    IInitializeWithStream streamInit = comObj as IInitializeWithStream;

                    bool isInitialized = false;
                    try
                    {
                        if (fileInit != null)
                        {
                            fileInit.Initialize(fileName, 0);
                            isInitialized = true;
                        }
                        else if (streamInit != null)
                        {
                            stream = new COMStream(File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read));
                            streamInit.Initialize((IStream)stream, 0);
                            isInitialized = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.Log.Warn("Unable to initialize IPreviewHandler", ex);
                    }

                    pHandler = comObj as IPreviewHandler;
                    if (isInitialized && pHandler != null)
                    {
                        RECT r = new RECT(viewRect);

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

                        pHandler.DoPreview();
                    }
                    else
                    {
                        Marshal.FinalReleaseComObject(comObj);
                        Release();
                    }
                }
            }
        }
Ejemplo n.º 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();
                        }
                    }
                }
            }
        }