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; }
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); }
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(); } } } } }