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