private static Bitmap capture(WebBrowser source, IntPtr hwnd) { HtmlDocument htmlDocument = source.Document; HtmlElement htmlElement = htmlDocument.Body; Rectangle rectangle = new Rectangle(new Point(0, 0), htmlElement.ScrollRectangle.Size); Bitmap image = new Bitmap(rectangle.Size.Width, rectangle.Size.Height, Graphics.FromHwnd(hwnd)); using (Graphics graphics = Graphics.FromImage(image)) { IOleObject oleObject = (IOleObject)htmlDocument.DomDocument; if (oleObject != null) { IntPtr imageDC = graphics.GetHdc(); IntPtr pUnk = Marshal.GetIUnknownForObject(source.ActiveXInstance); try { Size currentSize = new Size(); oleObject.GetExtent(DVASPECT.DVASPECT_CONTENT, out currentSize); Size drawingSize = convertPixelToHIMETRIC(rectangle.Size, imageDC); oleObject.SetExtent(DVASPECT.DVASPECT_CONTENT, ref drawingSize); OleDraw(pUnk, DVASPECT.DVASPECT_CONTENT, imageDC, ref rectangle); oleObject.SetExtent(DVASPECT.DVASPECT_CONTENT, ref currentSize); } finally { Marshal.Release(pUnk); graphics.ReleaseHdc(imageDC); } } graphics.Dispose(); } return(image); }
public void CreateDocument() { Debug.Assert(m_document == null, "Must call Close before recreating."); Boolean created = false; try { m_document = (IOleObject) new mshtml.HTMLDocument(); int iRetval = ComSupport.OleRun(m_document); m_document.SetClientSite(this); // Lock the object in memory iRetval = ComSupport.OleLockRunning(m_document, true, false); m_document.SetHostNames("HtmlEditor", "HtmlEditor"); m_document.Advise(this, out iAdviseCookie); created = true; } finally { if (created == false) { m_document = null; } } }
/// <summary> /// コンテンツのユーザー操作の可否を設定します。 /// </summary> /// <param name="isReadOnly">読み取り専用</param> private void SetReadOnly(bool isReadOnly) { try { // ボディー部を取得 HtmlDocument htmlDoc = Document; if (htmlDoc == null) { throw new NullReferenceException(); } HtmlElement element = htmlDoc.Body; if (element == null) { throw new NullReferenceException(); } IOleObject oleObj = (IOleObject)htmlDoc.DomDocument; if (oleObj == null) { throw new NullReferenceException(); } // 入力フィールド element.Parent.Enabled = !isReadOnly; } catch (NullReferenceException) { // OK } catch (Exception es) { ThreadExceptionDialog ed = new ThreadExceptionDialog(es); ed.ShowDialog(); } return; }
public void SetProxy() { if (ImageResolver.Instance.UseProxy) { var proxy = ImageResolver.Instance.GetCorrectCurrentWebProxy; if (proxy == null) { SetProxyServer(null); } else { object obj = webBrowser.ActiveXInstance; IOleObject oc = obj as IOleObject; oc.SetClientSite(this as IOleClientSite); _currentUsername = ImageResolver.Instance.ProxyUsers[proxy].UserName; _currentPassword = ImageResolver.Instance.ProxyUsers[proxy].Password; SetProxyServer(proxy.Address.ToString()); webBrowser.Navigate("about:blank"); Application.DoEvents(); } } else { SetProxyServer(null); } }
public static void LoadUrl(ref HTMLDocument doc, String url, bool CreateSite) { if (doc == null) { throw new HtmlEditorException("Null document passed to LoadDocument"); } if (CreateSite) { //set client site to DownloadOnlySite, to suppress scripts DownloadOnlySite ds = new DownloadOnlySite(); IOleObject ob = (IOleObject)doc; ob.SetClientSite(ds); } IPersistMoniker persistMoniker = (IPersistMoniker)doc; IMoniker moniker = null; int iResult = win32.CreateURLMoniker(null, url, out moniker); IBindCtx bindContext = null; iResult = win32.CreateBindCtx(0, out bindContext); iResult = persistMoniker.Load(0, moniker, bindContext, constants.STGM_READ); persistMoniker = null; bindContext = null; moniker = null; }
/// <summary> /// WORKBOOK EXTENSION METHOD /// This method return the name of the class that we /// are embedded inside of. /// If we are not embedded it return null. /// If there is any exception it return null. /// If the container cannot be accessed it returns UNKNOWN. /// </summary> /// <param name="PobjWb"></param> /// <returns></returns> public static string EmbedClassName(this Excel.Workbook PobjWb) { try { IOleObject LobjOleObject = ((object)PobjWb) as IOleObject; IOleClientSite LobjPpClientSite; // get the client site LobjOleObject.GetClientSite(out LobjPpClientSite); if (LobjPpClientSite != null) { IOleContainer LobjPpContainer; LobjPpClientSite.GetContainer(out LobjPpContainer); if (LobjPpContainer != null) { return(LobjPpContainer.GetType().Name); } else { // something wrong - container is not valid return("UNKNOWN"); } } else { // not embedded return(null); } } catch (Exception ex) { Debug.Print(ex.ToString()); return(null); // failed } }
public static void ComTypeInformation(object comObject, out string interfaceName, out string typeLibraryName, out string className) { interfaceName = null; typeLibraryName = null; className = null; //Get the object type information and the interface name GetTypeInterfaceName(comObject, out ComTypes.ITypeInfo comObjectTypeInformation, out interfaceName); //Get the type library name ComTypes.ITypeLib typeLibrary; try { comObjectTypeInformation.GetContainingTypeLib(out typeLibrary, out int index); typeLibraryName = Marshal.GetTypeLibName(typeLibrary); } catch { return; } //Get the class name IOleObject comObjectAsOleObject = comObject as IOleObject; if (comObjectAsOleObject == null) { return; } comObjectAsOleObject.GetUserClassID(out Guid classId); int typeInformationCount = typeLibrary.GetTypeInfoCount(); ComTypes.ITypeInfo typeInformation; ComTypes.TYPEATTR typeAttributes; IntPtr pointerTypeAttr = IntPtr.Zero; for (int index = typeInformationCount - 1; index > -1; index--) { typeLibrary.GetTypeInfo(index, out typeInformation); try { typeInformation.GetTypeAttr(out pointerTypeAttr); typeAttributes = (ComTypes.TYPEATTR)Marshal.PtrToStructure(pointerTypeAttr, TypeOfTypeAttr); if (classId == typeAttributes.guid) { className = Marshal.GetTypeInfoName(typeInformation); return; } } finally { if (pointerTypeAttr != IntPtr.Zero) { typeInformation.ReleaseTypeAttr(pointerTypeAttr); pointerTypeAttr = IntPtr.Zero; } } } }
private object CreateNewWebPage(string url) { TabPage tabPage = new TabPage("新标签页"); tabPage.Name = "tabPage" + (tabControl1.TabPages.Count + 1); WebPage webPage = new WebPage(); webPage.Dock = DockStyle.Fill; webPage.Tag = tabPage; webPage.NewPage += WebPage_NewPage; webPage.StatusTextChange += WebPage_StatusTextChange; webPage.TitleChange += WebPage_TitleChange; IOleObject obj = (IOleObject)webPage.GetActiveXInstance(); obj.SetClientSite(this); tabPage.Controls.Add(webPage); tabControl1.TabPages.Add(tabPage); tabControl1.SelectedTab = tabPage; if (url != null && url.Length > 0) { webPage.Navigate(url); } else { webPage.FocusAddressInput(); } return(webPage.GetActiveXInstance()); }
void OnButtonClicked(object sender, EventArgs e) { string resourcePath = "SampleBrowser.Samples.Presentation.Templates.EmbeddedOleObject.pptx"; Assembly assembly = Assembly.GetExecutingAssembly(); Stream fileStream = assembly.GetManifestResourceStream(resourcePath); IPresentation presentation = Presentation.Open(fileStream); //Gets the first slide of the Presentation ISlide slide = presentation.Slides[0]; //Gets the Ole Object of the slide IOleObject oleObject = slide.Shapes[2] as IOleObject; //Gets the file data of embedded Ole Object. byte[] array = oleObject.ObjectData; //Gets the file Name of OLE Object string outputFile = oleObject.FileName; MemoryStream stream = new MemoryStream(array); presentation.Close(); stream.Position = 0; if (stream != null) { SaveiOS iOSSave = new SaveiOS(); iOSSave.Save(outputFile, "application/msword", stream); } }
void OnInsertOleButtonClicked(object sender, EventArgs e) { Assembly assembly = Assembly.GetExecutingAssembly(); //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides]. IPresentation presentation = Syncfusion.Presentation.Presentation.Create(); ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly); IShape titleShape = slide.Shapes[0] as IShape; titleShape.Left = 0.65 * 72; titleShape.Top = 0.24 * 72; titleShape.Width = 11.5 * 72; titleShape.Height = 1.45 * 72; titleShape.TextBody.AddParagraph("Ole Object"); titleShape.TextBody.Paragraphs[0].Font.Bold = true; titleShape.TextBody.Paragraphs[0].HorizontalAlignment = HorizontalAlignmentType.Left; IShape heading = slide.Shapes.AddTextBox(100, 100, 100, 100); heading.Left = 0.84 * 72; heading.Top = 1.65 * 72; heading.Width = 2.23 * 72; heading.Height = 0.51 * 72; heading.TextBody.AddParagraph("MS Word Object"); heading.TextBody.Paragraphs[0].Font.Italic = true; heading.TextBody.Paragraphs[0].Font.Bold = true; heading.TextBody.Paragraphs[0].Font.FontSize = 18; string mswordPath = "SampleBrowser.Samples.Presentation.Templates.OleTemplate.docx"; //Get the word file as stream Stream wordStream = assembly.GetManifestResourceStream(mswordPath); string imagePath = "SampleBrowser.Samples.Presentation.Templates.OlePicture.png"; //Image to be displayed, This can be any image Stream imageStream = assembly.GetManifestResourceStream(imagePath); IOleObject oleObject = slide.Shapes.AddOleObject(imageStream, "Word.Document.12", wordStream); //Set size and position of the ole object oleObject.Left = 4.53 * 72; oleObject.Top = 0.79 * 72; oleObject.Width = 4.26 * 72; oleObject.Height = 5.92 * 72; //Set DisplayAsIcon as true, to open the embedded document in separate (default) application. oleObject.DisplayAsIcon = true; MemoryStream stream = new MemoryStream(); presentation.Save(stream); presentation.Close(); stream.Position = 0; if (stream != null) { SaveiOS iOSSave = new SaveiOS(); iOSSave.Save("InsertOLEObject.pptx", "application/mspowerpoint", stream); } }
public RemotedWindowsMediaPlayer() { // Create the Windows Media Player object Type type = Type.GetTypeFromCLSID(new Guid("6bf52a52-394a-11d3-b153-00c04f79faa6")); object instance = Activator.CreateInstance(type); //Get the IOleObject for Windows Media Player. IOleObject oleObject = instance as IOleObject; if (oleObject == null) { throw new Exception("Failed to get WMP OCX as an IOleObject?!"); } //Set the Client Site for the WMP control. oleObject.SetClientSite(this as IOleClientSite); // Try and get the OCX as a WMP player m_instance = instance as IWMPPlayer4; if (m_instance == null) { Marshal.FinalReleaseComObject(instance); throw new Exception(string.Format("OCX is not an IWMPPlayer4! GetType returns '{0}'", m_instance.GetType())); } }
private void CheckUIHostRegistration() { lock (_uiHostRegisteredLock) { if (testHelp != null) { testHelp.StartInfo = this.StartInfo; } if (isUIHostRegistered || ieInstance == null) { return; } ICustomDoc cDoc = ieInstance.Document as ICustomDoc; IOleObject oleObj = ieInstance.Document as IOleObject; if (oleObj != null && cDoc != null) { IOleClientSite clientSite = null; oleObj.GetClientSite(ref clientSite); if (cDoc != null) { _browser = new BrowserIEImpl(ieInstance, _mainHWND, _canvasHWND); testHelp = new IETestHelp(clientSite as IDocHostUIHandler, _browser, host); cDoc.SetUIHandler(testHelp); isUIHostRegistered = true; } } } }
private void btnCreatePresn_Click(object sender, EventArgs e) { //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides]. IPresentation presentation = Presentation.Create(); //Add slide with titleonly layout to presentation ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly); //Get the title placeholder IShape titleShape = slide.Shapes[0] as IShape; //Set size and position of the title shape titleShape.Left = 0.92 * 72; titleShape.Top = 0.4 * 72; titleShape.Width = 11.5 * 72; titleShape.Height = 1.01 * 72; //Add title content titleShape.TextBody.AddParagraph("Ole Object Demo"); //Set the title content as bold titleShape.TextBody.Paragraphs[0].Font.Bold = true; //Set the horizontal alignment as center titleShape.TextBody.Paragraphs[0].HorizontalAlignment = HorizontalAlignmentType.Center; //Add text box of specific size and position IShape heading = slide.Shapes.AddTextBox(3.2 * 72, 1.51 * 72, 1.86 * 72, 0.71 * 72); //Add paragraph to text box heading.TextBody.AddParagraph("MS Excel Object"); //Set the text content as italic heading.TextBody.Paragraphs[0].Font.Italic = true; //Set the text content as bold heading.TextBody.Paragraphs[0].Font.Bold = true; //Set the font size heading.TextBody.Paragraphs[0].Font.FontSize = 18; string excelPath = @"..\..\..\..\..\..\..\Common\Data\Presentation\OleTemplate.xlsx"; //Get the excel file as stream Stream excelStream = File.Open(excelPath, FileMode.Open); string imagePath = @"..\..\..\..\..\..\..\Common\Images\Presentation\OlePicture.png"; //Image to be displayed, This can be any image Stream imageStream = File.Open(imagePath, FileMode.Open); //Add ole object to the slide IOleObject oleObject = slide.Shapes.AddOleObject(imageStream, "Excel.Sheet.12", excelStream); //Set size and position of the ole object oleObject.Left = 3.29 * 72; oleObject.Top = 2.01 * 72; oleObject.Width = 6.94 * 72; oleObject.Height = 5.13 * 72; //Save the presentation presentation.Save("OleObjectSample.pptx"); //Close the presentation presentation.Close(); if (System.Windows.MessageBox.Show("Do you want to view the generated Presentation?", "Presentation Created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { System.Diagnostics.Process.Start("OleObjectSample.pptx"); this.Close(); } }
public override void RegisterDoc() { base.RegisterDoc(); if (registeredUIHandler == false) { registeredUIHandler = true; ICustomDoc cDoc = this.m_pIWebBrowser2.Document as ICustomDoc; IOleObject oleObj = this.m_pIWebBrowser2.Document as IOleObject; if (oleObj != null && cDoc != null) { IOleClientSite clientSite = null; oleObj.GetClientSite(ref clientSite); if (m_defaultUIHandler == null && clientSite != null) { m_defaultUIHandler = clientSite as IDocHostUIHandler; } if (cDoc != null) { cDoc.SetUIHandler(this); } } } }
/// <summary> /// Used to attach the appropriate interface to Windows Media Player. /// In here, we call SetClientSite on the WMP Control, passing it /// the dotNet container (this instance.) /// </summary> protected override void AttachInterfaces() { try { //Get the IOleObject for Windows Media Player. IOleObject oleObject = this.GetOcx() as IOleObject; if (oleObject != null) { //Set the Client Site for the WMP control. oleObject.SetClientSite(this as IOleClientSite); // Try and get the OCX as a WMP player if (this.GetOcx() as IWMPPlayer4 == null) { throw new Exception(string.Format("OCX is not an IWMPPlayer4! GetType returns '{0}'", this.GetOcx().GetType())); } } else { throw new Exception("Failed to get WMP OCX as an IOleObject?!"); } return; } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } }
public REOBJECT InsertOleObject(IOleObject oleObject, int index, int pos) { ILockBytes bytes; IStorage storage; IOleClientSite site; if (oleObject == null) { return(null); } NativeMethods.CreateILockBytesOnHGlobal(IntPtr.Zero, true, out bytes); NativeMethods.StgCreateDocfileOnILockBytes(bytes, 0x1012, 0, out storage); this.IRichEditOle.GetClientSite(out site); Guid pClsid = new Guid(); oleObject.GetUserClassID(ref pClsid); NativeMethods.OleSetContainedObject(oleObject, true); REOBJECT lpreobject = new REOBJECT { posistion = pos, clsid = pClsid, pstg = storage, poleobj = Marshal.GetIUnknownForObject(oleObject), polesite = site, dvAspect = 1, dwFlags = 2, dwUser = (uint)index }; this.IRichEditOle.InsertObject(lpreobject); Marshal.ReleaseComObject(bytes); Marshal.ReleaseComObject(site); Marshal.ReleaseComObject(storage); return(lpreobject); }
protected override void AttachInterfaces() { IOleObject oleObject = (IOleObject)this.GetOcx(); if (oleObject != null) { oleObject.SetClientSite((IOleClientSite)this); } }
private void Init() { //Get the IOleObject for Windows Media Player. IOleObject oleObject = this.GetOcx() as IOleObject; //Set the Client Site for the WMP control. oleObject.SetClientSite(this as IOleClientSite); Player = this.GetOcx() as WindowsMediaPlayer; }
/// <summary> /// Initializes OLE objects necessary for /// bypassing prompt dialogs /// </summary> public void InitializeOLE() { this.Navigate("about:blank"); while (this.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); } object obj = this.ActiveXInstance; IOleObject oc = obj as IOleObject; oc.SetClientSite(this as IOleClientSite); }
/// <summary> /// Create a simple Presentation document with OLE object /// </summary> /// <returns>Return the created Presentation document as stream</returns> public MemoryStream InsertOleObject() { //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides]. IPresentation presentation = Syncfusion.Presentation.Presentation.Create(); ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly); IShape titleShape = slide.Shapes[0] as IShape; titleShape.Left = 0.65 * 72; titleShape.Top = 0.24 * 72; titleShape.Width = 11.5 * 72; titleShape.Height = 1.45 * 72; titleShape.TextBody.AddParagraph("Ole Object"); titleShape.TextBody.Paragraphs[0].Font.Bold = true; titleShape.TextBody.Paragraphs[0].HorizontalAlignment = HorizontalAlignmentType.Left; IShape heading = slide.Shapes.AddTextBox(100, 100, 100, 100); heading.Left = 0.84 * 72; heading.Top = 1.65 * 72; heading.Width = 2.23 * 72; heading.Height = 0.51 * 72; heading.TextBody.AddParagraph("MS Word Object"); heading.TextBody.Paragraphs[0].Font.Italic = true; heading.TextBody.Paragraphs[0].Font.Bold = true; heading.TextBody.Paragraphs[0].Font.FontSize = 18; //Get the word file as stream Stream wordStream = new FileStream(ResolveApplicationPath("ole-template.docx"), FileMode.Open); //Image to be displayed, This can be any image string imagePath = _hostingEnvironment.WebRootPath + "//images//presentation//ole-picture.png"; Stream imageStream = new FileStream(imagePath, FileMode.Open); IOleObject oleObject = slide.Shapes.AddOleObject(imageStream, "Word.Document.12", wordStream); //Set size and position of the ole object oleObject.Left = 4.53 * 72; oleObject.Top = 0.79 * 72; oleObject.Width = 4.26 * 72; oleObject.Height = 5.92 * 72; //Set DisplayAsIcon as true, to open the embedded document in separate (default) application. oleObject.DisplayAsIcon = true; //Save the document as a stream and retrun the stream using (MemoryStream stream = new MemoryStream()) { //Save the created PowerPoint document to MemoryStream presentation.Save(stream); return(stream); } }
/// <summary> /// Add OLE objects necessary for bypassing prompt dialogs /// </summary> public void InitialiseOLE() { object obj = this.ActiveXInstance; IOleObject oc = obj as IOleObject; oc.SetClientSite(this as IOleClientSite); // Add Support for bypassing Proxy Authentication dialog AuthenticateProxy += delegate(object sender, EnhancedBrowser.AthenticateProxyEventArgs e) { e.Username = Proxy.Username; e.Password = Proxy.Password; }; }
public bool InsertImageFromFile(string strFilename, int position) { ILockBytes bytes; IStorage storage; IOleClientSite site; object obj2; NativeMethods.CreateILockBytesOnHGlobal(IntPtr.Zero, true, out bytes); NativeMethods.StgCreateDocfileOnILockBytes(bytes, 0x1012, 0, out storage); this.IRichEditOle.GetClientSite(out site); FORMATETC pFormatEtc = new FORMATETC { cfFormat = (CLIPFORMAT)0, ptd = IntPtr.Zero, dwAspect = DVASPECT.DVASPECT_CONTENT, lindex = -1, tymed = TYMED.TYMED_NULL }; Guid riid = new Guid("{00000112-0000-0000-C000-000000000046}"); Guid rclsid = new Guid("{00000000-0000-0000-0000-000000000000}"); NativeMethods.OleCreateFromFile(ref rclsid, strFilename, ref riid, 1, ref pFormatEtc, site, storage, out obj2); if (obj2 == null) { Marshal.ReleaseComObject(bytes); Marshal.ReleaseComObject(site); Marshal.ReleaseComObject(storage); return(false); } IOleObject pUnk = (IOleObject)obj2; Guid pClsid = new Guid(); pUnk.GetUserClassID(ref pClsid); NativeMethods.OleSetContainedObject(pUnk, true); REOBJECT lpreobject = new REOBJECT { posistion = position, clsid = pClsid, pstg = storage, poleobj = Marshal.GetIUnknownForObject(pUnk), polesite = site, dvAspect = 1, dwFlags = 2, dwUser = 0 }; this.IRichEditOle.InsertObject(lpreobject); Marshal.ReleaseComObject(bytes); Marshal.ReleaseComObject(site); Marshal.ReleaseComObject(storage); Marshal.ReleaseComObject(pUnk); return(true); }
public void HookUp(IOleObject obj) { if (obj == null) { throw new ArgumentNullException("obj"); } int rc = obj.SetClientSite(this); if (rc != 0) { throw new COMException(ErrorMessages.UnknownComError, rc); } }
public REOBJECT InsertOleObject( IOleObject oleObject, int index) { if (oleObject == null) { return(null); } ILockBytes pLockBytes; NativeMethods.CreateILockBytesOnHGlobal(IntPtr.Zero, true, out pLockBytes); IStorage pStorage; NativeMethods.StgCreateDocfileOnILockBytes( pLockBytes, (uint)(STGM.STGM_SHARE_EXCLUSIVE | STGM.STGM_CREATE | STGM.STGM_READWRITE), 0, out pStorage); IOleClientSite pOleClientSite; IRichEditOle.GetClientSite(out pOleClientSite); Guid guid = new Guid(); oleObject.GetUserClassID(ref guid); NativeMethods.OleSetContainedObject(oleObject, true); REOBJECT reoObject = new REOBJECT(); reoObject.cp = _richEdit.TextLength; reoObject.clsid = guid; reoObject.pstg = pStorage; reoObject.poleobj = Marshal.GetIUnknownForObject(oleObject); reoObject.polesite = pOleClientSite; reoObject.dvAspect = (uint)DVASPECT.DVASPECT_CONTENT; reoObject.dwFlags = (uint)REOOBJECTFLAGS.REO_BELOWBASELINE; reoObject.dwUser = (uint)index; IRichEditOle.InsertObject(reoObject); Marshal.ReleaseComObject(pLockBytes); Marshal.ReleaseComObject(pOleClientSite); Marshal.ReleaseComObject(pStorage); return(reoObject); }
protected void Button1_Click(object sender, EventArgs e) { //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides]. IPresentation presentation = Presentation.Create(); ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly); IShape titleShape = slide.Shapes[0] as IShape; titleShape.Left = 0.65 * 72; titleShape.Top = 0.24 * 72; titleShape.Width = 11.5 * 72; titleShape.Height = 1.45 * 72; titleShape.TextBody.AddParagraph("Ole Object"); titleShape.TextBody.Paragraphs[0].Font.Bold = true; titleShape.TextBody.Paragraphs[0].HorizontalAlignment = HorizontalAlignmentType.Left; IShape heading = slide.Shapes.AddTextBox(100, 100, 100, 100); heading.Left = 0.84 * 72; heading.Top = 1.65 * 72; heading.Width = 2.23 * 72; heading.Height = 0.51 * 72; heading.TextBody.AddParagraph("MS Word Object"); heading.TextBody.Paragraphs[0].Font.Italic = true; heading.TextBody.Paragraphs[0].Font.Bold = true; heading.TextBody.Paragraphs[0].Font.FontSize = 18; //Get the word file as stream using (Stream wordStream = File.Open(ResolveApplicationDataPath("OleTemplate.docx"), FileMode.Open)) { //Image to be displayed, This can be any image using (Stream imageStream = File.Open(ResolveApplicationImagePath("OlePicture.png"), FileMode.Open)) { IOleObject oleObject = slide.Shapes.AddOleObject(imageStream, "Word.Document.12", wordStream); //Set size and position of the ole object oleObject.Left = 4.53 * 72; oleObject.Top = 0.79 * 72; oleObject.Width = 4.26 * 72; oleObject.Height = 5.92 * 72; //Set DisplayAsIcon as true, to open the embedded document in separate (default) application. oleObject.DisplayAsIcon = true; //Saves the presentation presentation.Save("InsertOLEObject.pptx", FormatType.Pptx, Response); wordStream.Close(); imageStream.Close(); } } }
public void HookUp(WebBrowserBase webBrowser) { if (webBrowser == null) { throw new ArgumentNullException("webBrowser"); } IOleObject oleObject = (IOleObject)webBrowser.ActiveXInstance; int rc = oleObject.SetClientSite(this); if (rc != 0) { throw new COMException(ErrorMessages.UnknownComError, rc); } }
public ExplorerBrowserControlClientSite(object browser) { // Set us as the client site // // It seems a bit dodgy to set ourselves as the client site since we don't // implement all the interfaces that may be exposed by the provided client site. It // appears, however, that none of those interfaces are called once the browserControl // has been loaded, so this appears safe. See the description in the links below for // additional discussion. // // http://www.codeproject.com/books/0764549146_8.asp // http://discuss.develop.com/archives/wa.exe?A2=ind0205A&L=DOTNET&D=0&P=15756 IOleObject oleObject = (IOleObject)browser; oleObject.SetClientSite(this); }
protected void Button1_Click(object sender, EventArgs e) { //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides]. IPresentation presentation = Presentation.Create(); ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly); IShape titleShape = slide.Shapes[0] as IShape; titleShape.Left = 0.92 * 72; titleShape.Top = 0.4 * 72; titleShape.Width = 11.5 * 72; titleShape.Height = 1.01 * 72; titleShape.TextBody.AddParagraph("Ole Object Demo"); titleShape.TextBody.Paragraphs[0].Font.Bold = true; titleShape.TextBody.Paragraphs[0].HorizontalAlignment = HorizontalAlignmentType.Center; IShape heading = slide.Shapes.AddTextBox(100, 100, 100, 100); heading.Left = 3.2 * 72; heading.Top = 1.51 * 72; heading.Width = 1.86 * 72; heading.Height = 0.71 * 72; heading.TextBody.AddParagraph("MS Excel Object"); heading.TextBody.Paragraphs[0].Font.Italic = true; heading.TextBody.Paragraphs[0].Font.Bold = true; heading.TextBody.Paragraphs[0].Font.FontSize = 18; //Get the excel file as stream using (Stream excelStream = File.Open(ResolveApplicationDataPath("OleTemplate.xlsx"), FileMode.Open)) { //Image to be displayed, This can be any image using (Stream imageStream = File.Open(ResolveApplicationImagePath("OlePicture.png"), FileMode.Open)) { IOleObject oleObject = slide.Shapes.AddOleObject(imageStream, "Excel.Sheet.12", excelStream); //Set size and position of the ole object oleObject.Left = 3.29 * 72; oleObject.Top = 2.01 * 72; oleObject.Width = 6.94 * 72; oleObject.Height = 5.13 * 72; //Saves the presentation presentation.Save("InsertOLESample.pptx", FormatType.Pptx, Response); excelStream.Close(); imageStream.Close(); } } }
public void DoInterfaceAttachment() { try { //Get the IOleObject for Windows Media Player. _oleObject = this.GetOcx() as IOleObject; //Set the Client Site for the WMP control. _oleObject.SetClientSite(this as IOleClientSite); this.ocx = ((WMPLib.IWMPPlayer4)(this.GetOcx())); } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } }
public void Navicate(string Url) { try { if (webBrowser != null) { this.webBrowser.Navigate(Url); object obj = webBrowser.ActiveXInstance; oc = obj as IOleObject; oc.SetClientSite(this as IOleClientSite); } } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); } }
cHTMLParser() { //Create a new MSHTML, throws exception if fails Type htmldoctype = Type.GetTypeFromCLSID(Iid_Clsids.CLSID_HTMLDocument, true); //Using Activator inplace of CoCreateInstance, returns IUnknown //which we cast to a IHtmlDocument2 interface m_pMSHTML = (IHTMLDocument2)System.Activator.CreateInstance(htmldoctype); //Get the IOleObject m_WBOleObject = (IOleObject)m_pMSHTML; //Set client site int iret = m_WBOleObject.SetClientSite(this); //Connect for IPropertyNotifySink m_WBOleControl = (IOleControl)m_pMSHTML; m_WBOleControl.OnAmbientPropertyChange(HTMLDispIDs.DISPID_AMBIENT_DLCONTROL); //Get connectionpointcontainer IConnectionPointContainer cpCont = (IConnectionPointContainer)m_pMSHTML; cpCont.FindConnectionPoint(ref Iid_Clsids.IID_IPropertyNotifySink, out m_WBConnectionPoint); //Advice m_WBConnectionPoint.Advise(this, out m_dwCookie); }
public REOBJECT InsertOleObject(IOleObject oleObject, int index, int pos) { if (oleObject == null) { return null; } ILockBytes pLockBytes; NativeMethods.CreateILockBytesOnHGlobal(IntPtr.Zero, true, out pLockBytes); IStorage pStorage; NativeMethods.StgCreateDocfileOnILockBytes( pLockBytes, (uint)(STGM.STGM_SHARE_EXCLUSIVE | STGM.STGM_CREATE | STGM.STGM_READWRITE), 0, out pStorage); IOleClientSite pOleClientSite; IRichEditOle.GetClientSite(out pOleClientSite); Guid guid = new Guid(); oleObject.GetUserClassID(ref guid); NativeMethods.OleSetContainedObject(oleObject, true); REOBJECT reoObject = new REOBJECT(); reoObject.posistion = pos; reoObject.clsid = guid; reoObject.pstg = pStorage; reoObject.poleobj = Marshal.GetIUnknownForObject(oleObject); reoObject.polesite = pOleClientSite; reoObject.dvAspect = (uint)DVASPECT.DVASPECT_CONTENT; reoObject.dwFlags = (uint)REOOBJECTFLAGS.REO_BELOWBASELINE; reoObject.dwUser = (uint)index; IRichEditOle.InsertObject(reoObject); Marshal.ReleaseComObject(pLockBytes); Marshal.ReleaseComObject(pOleClientSite); Marshal.ReleaseComObject(pStorage); return reoObject; }
public void HookUp( IOleObject obj ) { if ( obj == null ) { throw new ArgumentNullException( "obj" ); } int rc = obj.SetClientSite( this ); if ( rc != 0 ) { throw new COMException( ErrorMessages.UnknownComError, rc ); } }
public void StopParsing() { try { //UnAdvice and clean up if ((m_WBConnectionPoint != null) && (m_dwCookie > 0)) m_WBConnectionPoint.Unadvise(m_dwCookie); if (m_WBOleObject != null) { m_WBOleObject.Close((uint)OLEDOVERB.OLECLOSE_NOSAVE); m_WBOleObject.SetClientSite(null); } if (m_pMSHTML != null) { Marshal.ReleaseComObject(m_pMSHTML); m_pMSHTML = null; } if (m_WBConnectionPoint != null) { Marshal.ReleaseComObject(m_WBConnectionPoint); m_WBConnectionPoint = null; } if (m_WBOleControl != null) { Marshal.ReleaseComObject(m_WBOleControl); m_WBOleControl = null; } if (m_WBOleObject != null) { Marshal.ReleaseComObject(m_WBOleObject); m_WBOleObject = null; } } catch (Exception) { throw; } }
/// <summary> /// Only public method which starts the parsing process /// When parsing is done, we receive a DISPID_READYSTATE dispid /// in IPropertyNotifySink.OnChanged implementation /// </summary> /// <param name="Url"></param> /// <param name="cookie"></param> public void StartParsing(string Url, string cookie) { IntPtr pUsername = IntPtr.Zero; IntPtr pPassword = IntPtr.Zero; try { if (string.IsNullOrEmpty(Url)) throw new ApplicationException("Url must have a valid value!"); //Create a new MSHTML, throws exception if fails Type htmldoctype = Type.GetTypeFromCLSID(Iid_Clsids.CLSID_HTMLDocument, true); //Using Activator inplace of CoCreateInstance, returns IUnknown //which we cast to a IHtmlDocument2 interface m_pMSHTML = (IHTMLDocument2)System.Activator.CreateInstance(htmldoctype); //Get the IOleObject m_WBOleObject = (IOleObject)m_pMSHTML; //Set client site int iret = m_WBOleObject.SetClientSite(this); //Connect for IPropertyNotifySink m_WBOleControl = (IOleControl)m_pMSHTML; m_WBOleControl.OnAmbientPropertyChange(HTMLDispIDs.DISPID_AMBIENT_DLCONTROL); //Get connectionpointcontainer IConnectionPointContainer cpCont = (IConnectionPointContainer)m_pMSHTML; cpCont.FindConnectionPoint(ref Iid_Clsids.IID_IPropertyNotifySink, out m_WBConnectionPoint); //Advice m_WBConnectionPoint.Advise(this, out m_dwCookie); m_Done = false; m_Url = Url; if (!string.IsNullOrEmpty(cookie)) m_pMSHTML.cookie = cookie; //Set up username and password if provided if (!string.IsNullOrEmpty(m_Username)) { pUsername = Marshal.StringToCoTaskMemAnsi(m_Username); if (pUsername != IntPtr.Zero) WinApis.InternetSetOption(IntPtr.Zero, InternetSetOptionFlags.INTERNET_OPTION_USERNAME, pUsername, m_Username.Length); } if (!string.IsNullOrEmpty(m_Password)) { pPassword = Marshal.StringToCoTaskMemAnsi(m_Password); if (pPassword != IntPtr.Zero) WinApis.InternetSetOption(IntPtr.Zero, InternetSetOptionFlags.INTERNET_OPTION_PASSWORD, pPassword, m_Password.Length); } //Load IPersistMoniker persistMoniker = (IPersistMoniker)m_pMSHTML; IMoniker moniker = null; WinApis.CreateURLMoniker(null, m_Url, out moniker); if (moniker == null) return; IBindCtx bindContext = null; WinApis.CreateBindCtx((uint)0, out bindContext); if (bindContext == null) return; persistMoniker.Load(1, moniker, bindContext, 0); } catch (Exception) { throw; } finally { if (pUsername != IntPtr.Zero) Marshal.FreeCoTaskMem(pUsername); if (pPassword != IntPtr.Zero) Marshal.FreeCoTaskMem(pPassword); } }
public static extern int OleLoadFromStream(IStream pStorage, ref Guid iid, out IOleObject pObject);
protected override void Dispose(bool disposing) { if ((disposing) && (!this.DesignMode)) { if (m_HookHandled != IntPtr.Zero) Marshal.FreeHGlobal(m_HookHandled); if (m_WBThumbImg != null) m_WBThumbImg.Dispose(); InternalFreeWB(); if ((components != null)) components.Dispose(); // New Stuff m_WBWebBrowser2 = null; m_WBUnknown = null; m_WBOleObject = null; m_WBOleInPlaceObject = null; m_WBOleCommandTarget = null; RemoveDocumentChangeNotification(); RemoveIUtilManEvents(); RemCOMLibrary(); // ParentWindow.onload should be nulled // the frames also //(IHTMLWindow2)doc2.parentWindow DocumentComplete = null; BeforeNavigate2 = null; ClientToHostWindow = null; CommandStateChange = null; DownloadBegin = null; DownloadComplete = null; FileDownload = null; NavigateComplete2 = null; NavigateError = null; NewWindow2 = null; NewWindow3 = null; PrintTemplateInstantiation = null; PrintTemplateTeardown = null; PrivacyImpactedStateChange = null; ProgressChange = null; PropertyChange = null; SetSecureLockIcon = null; StatusTextChange = null; TitleChange = null; WindowClosing = null; WindowSetHeight = null; WindowSetLeft = null; WindowSetResizable = null; WindowSetTop = null; WindowSetWidth = null; WBDragEnter = null; WBDragLeave = null; WBDragOver = null; WBDragDrop = null; WBKeyDown = null; WBKeyUp = null; WBContextMenu = null; WBGetOptionKeyPath = null; WBDocHostShowUIShowMessage = null; DocumentCompleteEX = null; WBAuthenticate = null; WBSecurityProblem = null; WBEvaluteNewWindow = null; ScriptError = null; UpdatePageStatus = null; RefreshBegin = null; RefreshEnd = null; ProcessUrlAction = null; AllowFocusChange = null; HTMLOMWindowServices_moveTo = null; HTMLOMWindowServices_moveBy = null; HTMLOMWindowServices_resizeTo = null; HTMLOMWindowServices_resizeBy = null; WBLButtonDown = null; WBLButtonUp = null; WBMouseMove = null; AuthenticationEvent = null; } base.Dispose(disposing); }
public void CloseDocument() { try { container.releaseWndProc(); container.Resize -= new EventHandler(this.Container_Resize); if (m_document == null) return; try { //this may raise an exception, however it does work and must //be called if (view != null) { view.Show(-1); view.UIActivate(-1); view.SetInPlaceSite(null); view.CloseView(0); } } catch (Exception e) { Debug.WriteLine("CloseView raised exception: " + e.Message); } try { //this could raise an exception too, but it must be called m_document.Close((int)tagOLECLOSE.OLECLOSE_NOSAVE); } catch (Exception e) { Debug.WriteLine("Close document raised exception: " + e.Message); } m_document.SetClientSite(null); win32.OleLockRunning(m_document, false, false); if (this.iAdviseCookie != 0) { m_document.Unadvise(this.iAdviseCookie); } if (this.iEventsCookie != 0) { m_document.Unadvise(this.iEventsCookie); } if (this.iPropertyNotifyCookie != 0) { m_document.Unadvise(this.iPropertyNotifyCookie); } if (container.changeCookie != 0) { ((IMarkupContainer2)m_document).UnRegisterForDirtyRange(container.changeCookie); container.changeCookie = 0; } //release COM objects int RefCount = 0; if (m_document != null) do { RefCount = Marshal.ReleaseComObject(m_document); } while (RefCount > 0); if (view != null) do { RefCount = Marshal.ReleaseComObject(view); } while (RefCount > 0); if (activeObject != null) do { RefCount = Marshal.ReleaseComObject(activeObject); } while (RefCount > 0); if (snapper != null) { IntPtr ppinterface = Marshal.GetComInterfaceForObject(snapper, typeof(IHTMLEditHost)); if (ppinterface != null) { do { RefCount = Marshal.Release(ppinterface); } while (RefCount > 0); } snapper = null; } m_document = null; view = null; activeObject = null; container.mHtmlDoc = null; container.mDocHTML = null; } catch (Exception e) { Debug.WriteLine("CloseDocument raised exception: " + e.Message); } }
public REOBJECT InsertOleObject(IOleObject oleObject, int index) { return this.InsertOleObject(oleObject, index, agileRichTextBox.TextLength); }
public void CreateDocument() { Debug.Assert(m_document == null, "Must call Close before recreating."); Boolean created = false; try { m_document = (IOleObject)new HTMLDocument(); int iRetval; iRetval = win32.OleRun(m_document); iRetval = m_document.SetClientSite(this); Debug.Assert(iRetval == HRESULT.S_OK, "SetClientSite failed"); // Lock the object in memory iRetval = win32.OleLockRunning(m_document, true, false); m_document.SetHostNames("HtmlEditor", "HtmlEditor"); m_document.Advise(this, out iAdviseCookie); //hook up HTMLDocumentEvents2 Guid guid = new Guid("3050f613-98b5-11cf-bb82-00aa00bdce0b"); IConnectionPointContainer icpc = (IConnectionPointContainer)m_document; icpc.FindConnectionPoint(ref guid, out icp); icp.Advise(this, out iEventsCookie); created = true; } finally { if (created == false) m_document = null; } }
/// <summary> /// Create Webbrowser control and set up it's events /// called from OnHandleCreated /// Webbrowser control hosting requires an HWND /// </summary> /// <returns></returns> private void InternalCreateWB() { //Create a new WB, throws exception if fails Type webbrowsertype = Type.GetTypeFromCLSID(Iid_Clsids.CLSID_WebBrowser, true); //Using Activator inplace of CoCreateInstance, returns IUnknown m_WBUnknown = System.Activator.CreateInstance(webbrowsertype); //Get the IOleObject m_WBOleObject = (IOleObject)m_WBUnknown; //Set client site int iret = m_WBOleObject.SetClientSite(this); //Set hostnames iret = m_WBOleObject.SetHostNames("csEXWB", string.Empty); //Get client rect bool brect = WinApis.GetClientRect(this.Handle, out m_WBRect); //Setup H+W m_WBRect.Right = m_WBRect.Right - m_WBRect.Left; //W m_WBRect.Bottom = m_WBRect.Bottom - m_WBRect.Top; //H m_WBRect.Left = 0; m_WBRect.Top = 0; //Get the IOleInPlaceObject m_WBOleInPlaceObject = (IOleInPlaceObject)m_WBUnknown; tagRECT trect = new tagRECT(); WinApis.CopyRect(ref trect, ref m_WBRect); //Set WB rects iret = m_WBOleInPlaceObject.SetObjectRects(ref m_WBRect, ref trect); //INPLACEACTIVATE the WB iret = m_WBOleObject.DoVerb((int)OLEDOVERB.OLEIVERB_INPLACEACTIVATE, ref m_NullMsg, this, 0, this.Handle, ref m_WBRect); //Get the IWebBrowser2 m_WBWebBrowser2 = (IWebBrowser2)m_WBUnknown; //By default, we handle dragdrops m_WBWebBrowser2.RegisterAsDropTarget = false; if (!DesignMode) { //Get connectionpointcontainer IConnectionPointContainer cpCont = (IConnectionPointContainer)m_WBUnknown; //Find connection point Guid guid = typeof(DWebBrowserEvents2).GUID; IConnectionPoint m_WBConnectionPoint = null; cpCont.FindConnectionPoint(ref guid, out m_WBConnectionPoint); //Advice m_WBConnectionPoint.Advise(this, out m_dwCookie); //Get the IOleComandTarget m_WBOleCommandTarget = (IOleCommandTarget)m_WBUnknown; //Reguster clipborad format for internal drag drop //RegisterClipboardFormatsForDragDrop(); } if (!string.IsNullOrEmpty(m_sUrl)) this.Navigate(m_sUrl); else this.Navigate("about:blank"); //Get the shell embedding, ... WBIEServerHandle(); }
//Registers clipboard formats that we can handle //Registered Dragdrop formats //private short m_CFHTML = 0; //private short m_CFRTF = 0; //private short m_CFURL = 0; //private short m_CFNETRESOURCE = 0; //private short m_CFUNTRUSTEDDRAGDROP = 0; //private short m_CFFILEGROUPDESCRIPTOR = 0; //private short m_CFFILECONTENTS = 0; //private void RegisterClipboardFormatsForDragDrop() //{ // m_CFHTML = (short)WinApis.RegisterClipboardFormat("HTML Format"); // m_CFRTF = (short)WinApis.RegisterClipboardFormat("Rich Text Format"); // m_CFFILEGROUPDESCRIPTOR = (short)WinApis.RegisterClipboardFormat("FileGroupDescriptor"); // m_CFFILECONTENTS = (short)WinApis.RegisterClipboardFormat("FileContents"); // m_CFUNTRUSTEDDRAGDROP = (short)WinApis.RegisterClipboardFormat("UntrustedDragDrop"); // m_CFURL = (short)WinApis.RegisterClipboardFormat("UniformResourceLocator"); // m_CFNETRESOURCE = (short)WinApis.RegisterClipboardFormat("Net Resource"); //} private void InternalFreeWB() { if( (!DesignMode) && (m_WBUnknown != null) ) { //Get connectionpointcontainer IConnectionPointContainer cpCont = m_WBUnknown as IConnectionPointContainer; //Find connection point if (cpCont != null) { Guid guid = typeof(DWebBrowserEvents2).GUID; IConnectionPoint m_WBConnectionPoint = null; cpCont.FindConnectionPoint(ref guid, out m_WBConnectionPoint); //UnAdvice if ((m_WBConnectionPoint != null) && (m_dwCookie > 0)) m_WBConnectionPoint.Unadvise(m_dwCookie); } //UI and Inplace deactivate if (m_WBOleInPlaceObject != null) { m_WBOleInPlaceObject.UIDeactivate(); m_WBOleInPlaceObject.InPlaceDeactivate(); } //Disconnect from ole if (m_WBOleObject != null) { m_WBOleObject.Close((uint)OLEDOVERB.OLECLOSE_NOSAVE); m_WBOleObject.SetClientSite(null); } } if (m_txtrange != null) { Marshal.ReleaseComObject(m_txtrange); m_txtrange = null; } if (m_WBOleCommandTarget != null) { Marshal.ReleaseComObject(m_WBOleCommandTarget); m_WBOleCommandTarget = null; } if (m_WBWebBrowser2 != null) { Marshal.ReleaseComObject(m_WBWebBrowser2); m_WBWebBrowser2 = null; } if (m_WBOleInPlaceObject != null) { Marshal.ReleaseComObject(m_WBOleInPlaceObject); m_WBOleCommandTarget = null; } if (m_WBOleObject != null) { Marshal.ReleaseComObject(m_WBOleObject); m_WBOleObject = null; } if (m_WBUnknown != null) { Marshal.ReleaseComObject(m_WBUnknown); m_WBUnknown = null; } if (m_WantHtmlDocumentEvents) { m_TopLevelHtmlDocumentevents.DisconnectHtmlEvents(); DisconnectHtmlDocumentEvents(); } if (m_WantHtmlWindowEvents) { m_TopLevelHtmlWindowEvents.DisconnectHtmlEvents(); DisconnectHtmlWindowEvnets(); } if (m_Subclassed) { StopSubclass(); } }
public void InsertOleObject(IOleObject oleObject) { if (oleObject == null) return; //----------------------- ILockBytes pLockBytes; CreateILockBytesOnHGlobal(IntPtr.Zero, true, out pLockBytes); IStorage pStorage; StgCreateDocfileOnILockBytes(pLockBytes, (uint)(STGM.STGM_SHARE_EXCLUSIVE|STGM.STGM_CREATE|STGM.STGM_READWRITE), 0, out pStorage); IOleClientSite pOleClientSite; this.IRichEditOle.GetClientSite(out pOleClientSite); //----------------------- //----------------------- Guid guid = new Guid(); oleObject.GetUserClassID(ref guid); //----------------------- //----------------------- OleSetContainedObject(oleObject, true); REOBJECT reoObject = new REOBJECT(); reoObject.cp = this._richEdit.TextLength; reoObject.clsid = guid; reoObject.pstg = pStorage; reoObject.poleobj = Marshal.GetIUnknownForObject(oleObject); reoObject.polesite = pOleClientSite; reoObject.dvAspect = (uint)DVASPECT.DVASPECT_CONTENT; reoObject.dwFlags = (uint)REOOBJECTFLAGS.REO_BELOWBASELINE; this.IRichEditOle.InsertObject(reoObject); //----------------------- //----------------------- Marshal.ReleaseComObject(pLockBytes); Marshal.ReleaseComObject(pOleClientSite); Marshal.ReleaseComObject(pStorage); //----------------------- }
public void InsertOleObject(IOleObject oleObj) { RichEditOle ole = new RichEditOle(this); ole.InsertOleObject(oleObj); }