/// <summary> /// </summary> public void CloseMSHTML() { hostControl.Resize -= new EventHandler(this.OnParentResize); try { if (propNotifyCookie != null) { propNotifyCookie.Disconnect(); propNotifyCookie = null; } if (tridentDocument != null) { tridentView = null; tridentDocument = null; tridentCmdTarget = null; activeObject = null; if (adviseSinkCookie != 0) { tridentOleObject.Unadvise(adviseSinkCookie); adviseSinkCookie = 0; } tridentOleObject.Close(Interop.OLECLOSE_NOSAVE); tridentOleObject.SetClientSite(null); tridentOleObject = null; } } catch (Exception e) { Debug.Fail(e.ToString()); } }
/// <summary> /// </summary> public void CreateMSHTML() { Debug.Assert(tridentDocument == null, "Must call CloseMSHTML before recreating."); bool created = false; try { // create the trident instance tridentDocument = (Interop.IHTMLDocument2) new Interop.HTMLDocument(); tridentOleObject = (Interop.IOleObject)tridentDocument; // hand it our Interop.IOleClientSite implementation tridentOleObject.SetClientSite((Interop.IOleClientSite) this); created = true; propNotifyCookie = new Interop.ConnectionPointCookie(tridentDocument, this, typeof(Interop.IPropertyNotifySink), false); tridentOleObject.Advise((Interop.IAdviseSink) this, out adviseSinkCookie); Debug.Assert(adviseSinkCookie != 0); tridentCmdTarget = (Interop.IOleCommandTarget)tridentDocument; } finally { if (created == false) { tridentDocument = null; tridentOleObject = null; tridentCmdTarget = null; } } }
void SelfHandleCreated(object s, EventArgs e) { HandleCreated -= new EventHandler(SelfHandleCreated); if (url == null) { url = String.Empty; } if (html == null) { html = String.Empty; } if (body == null) { body = String.Empty; } if (body == String.Empty && html == String.Empty) { url = "about:blank"; } _uiHandler = new DocHostUIHandler(this); // need to SetClientSite() to enable set properties in GetHostInfo() and setFlags(): Interop.IOleObject oleObj = control as Interop.IOleObject; if (oleObj != null) { oleObj.SetClientSite(_uiHandler); } BrowserEvents2Multicaster bec = new BrowserEvents2Multicaster(this); Navigate(url); }
/// <summary> /// </summary> public void CreateMSHTML() { bool created = false; try { // create our base instance this.htmlbaseDocument = (Interop.IHTMLDocument2) new Interop.HTMLDocument(); this.activeObject = (Interop.IOleInPlaceActiveObject)htmlbaseDocument; this.windowHandle = new IntPtr(); this.activeObject.GetWindow(out this.windowHandle); oleDocumentObject = (Interop.IOleObject)htmlbaseDocument; if (oleDocumentObject == null) { throw new ApplicationException("InteropOleObject not created. No document available."); } // hand it our Interop.IOleClientSite implementation Win32.OleRun(htmlbaseDocument); oleDocumentObject.SetClientSite(this); Win32.OleLockRunning(htmlbaseDocument, true, false); created = true; // attach document and window base events propNotifyCookie = new ConnectionPointCookie(htmlbaseDocument, this, typeof(Interop.IPropertyNotifySink), false); // set document properties oleDocumentObject.SetHostNames("NetRix", "NetRix"); // set ole events oleDocumentObject.Advise(this, out adviseSinkCookie); // set IConnectionPointContainer icpc = (IConnectionPointContainer)htmlbaseDocument; //find the source interface ////get IPropertyNotifySink interface //Guid g = new Guid("9BFBBC02-EFF1-101A-84ED-00AA00341D07"); //icpc.FindConnectionPoint(ref g, out icp); ////pass a pointer to the host to the connection point //icp.Advise(this._site, out this._cookie); } catch (Exception ex) { Debug.Fail("CreateHtml failed", ex.Message); } finally { if (created == false) { htmlbaseDocument = null; oleDocumentObject = null; } } }
public void CloseMSHTML() { this.hostControl.Resize -= new EventHandler(this.OnParentResize); try { if (this.propNotifyCookie != null) { this.propNotifyCookie.Disconnect(); this.propNotifyCookie = null; } if (this.tridentDocument != null) { this.tridentView = null; this.tridentDocument = null; this.tridentCmdTarget = null; this.activeObject = null; if (this.adviseSinkCookie != 0) { this.tridentOleObject.Unadvise(this.adviseSinkCookie); this.adviseSinkCookie = 0; } this.tridentOleObject.Close(1); this.tridentOleObject.SetClientSite(null); this.tridentOleObject = null; } } catch (Exception) { } }
public void CreateMSHTML() { bool flag = false; try { this.tridentDocument = (Interop.IHTMLDocument2) new Interop.HTMLDocument(); this.tridentOleObject = (Interop.IOleObject) this.tridentDocument; this.tridentOleObject.SetClientSite(this); flag = true; this.propNotifyCookie = new Interop.ConnectionPointCookie(this.tridentDocument, this, typeof(Interop.IPropertyNotifySink), false); this.tridentOleObject.Advise(this, out this.adviseSinkCookie); this.tridentCmdTarget = (Interop.IOleCommandTarget) this.tridentDocument; } finally { if (!flag) { this.tridentDocument = null; this.tridentOleObject = null; this.tridentCmdTarget = null; } } }
/// <summary> /// </summary> public void Dispose() { try { int RefCount; if (propNotifyCookie != null) { propNotifyCookie.Dispose(); propNotifyCookie = null; } if (winEvents != null) { winEvents.Dispose(); winEvents = null; } try { Marshal.ReleaseComObject(window); } catch { } try { if (interopDocumentView != null) { try { interopDocumentView.Show(0); } catch { } try { interopDocumentView.UIActivate(0); } catch { } try { interopDocumentView.SetInPlaceSite(null); } catch { } long nullParam = 0L; try { interopDocumentView.Close(nullParam); do { RefCount = Marshal.ReleaseComObject(interopDocumentView); } while (RefCount >= 0); } catch { } finally { Marshal.FinalReleaseComObject(interopDocumentView); interopDocumentView = null; } } } catch { } if (oleDocumentObject != null) { try { if (htmlEditor.Site == null || !htmlEditor.Site.DesignMode) { Marshal.FinalReleaseComObject(oleDocumentObject); oleDocumentObject = null; } } catch { } } if (htmlbaseDocument != null) { do { RefCount = Marshal.ReleaseComObject(htmlbaseDocument); } while (RefCount >= 0); Marshal.FinalReleaseComObject(htmlbaseDocument); htmlbaseDocument = null; } if (interopDocumentView != null) { do { RefCount = Marshal.ReleaseComObject(interopDocumentView); } while (RefCount >= 0); } if (activeObject != null) { do { RefCount = Marshal.ReleaseComObject(activeObject); } while (RefCount >= 0); Marshal.FinalReleaseComObject(activeObject); activeObject = null; } interopDocumentView = null; htmlbaseDocument = null; activeObject = null; } catch (Exception ex) { Debug.WriteLine(ex.Message); } }