public void CloseHtml() { this.hostControl.Resize -= new EventHandler(this.HostControl_Resize); try { if (this.propertyNotifySinkCookie != null) { this.propertyNotifySinkCookie.Disconnect(); this.propertyNotifySinkCookie = null; } if (this.document != null) { this.documentView = null; this.document = null; this.commandTarget = null; this.activeObject = null; if (adviseSinkCookie != 0) { this.oleObject.Unadvise(adviseSinkCookie); this.adviseSinkCookie = 0; } this.oleObject.Close(NativeMethods.OLECLOSE_NOSAVE); this.oleObject.SetClientSite(null); this.oleObject = null; } } catch (Exception exception) { Debug.Fail(exception.ToString()); } }
/// <include file='doc\MSHTMLHost.uex' path='docs/doc[@for="TridentSite.CloseDocument"]/*' /> /// <devdoc> /// Closes the mshtml instance by deactivating and releasing it. /// </devdoc> protected void CloseDocument() { try { if (tridentDocument != null) { if (tridentView != null) { tridentView.UIActivate(0); tridentView.SetInPlaceSite(null); tridentView = null; } tridentDocument = null; // Change 1: // After 2 days of investigation... this is all that came out of it (!)... // Calling IOleObject::Close does not seem to work (you guessed it... in the StyleBuilder only) // It causes the app to hang around forever; very bizarre // // Anyway, from Trident sources, they handle the case where a container does not call // Close, and releases references directly // // I thought maybe I should call DoVerb(OLEIVERB_HIDE) at least. // It seems to work, but it theres also some code in trident that says HIDE should not be // called when its running in MsoDocMode. Whats that? For now I am calling it. // // tridentOleObject.Close(NativeMethods.OLECLOSE_NOSAVE); // Change 2: // Furthermore, it looks like I can't call DoVerb(OLEIVERB_HIDE) for docobjects... // We get back E_UNEXPECTED. Apparently the right thing to do is to call // IOleDocumentView::UIActivate(0) and IOleDocumentView::SetInPlaceSite(null) // both of which I am now doing above // // Debug.Assert(parentControl.IsHandleCreated); // NativeMethods.COMRECT r = new NativeMethods.COMRECT(); // NativeMethods.GetClientRect(parentControl.Handle, r); // // tridentOleObject.DoVerb(NativeMethods.OLEIVERB_HIDE, IntPtr.Zero, (NativeMethods.IOleClientSite)this, 0, // parentControl.Handle, r.ToWin32InteropCOMRECT()); tridentOleObject.SetClientSite(null); tridentOleObject = null; } } catch (Exception e) { Debug.Fail(e.ToString()); } }
/// <include file='doc\MSHTMLHost.uex' path='docs/doc[@for="TridentSite.CloseDocument"]/*' /> /// <devdoc> /// Closes the mshtml instance by deactivating and releasing it. /// </devdoc> protected void CloseDocument() { try { if (tridentDocument != null) { tridentView = null; tridentDocument = null; tridentOleObject.Close(NativeMethods.OLECLOSE_NOSAVE); tridentOleObject.SetClientSite(null); tridentOleObject = null; } } catch (Exception e) { Debug.Fail(e.ToString()); } }
/////////////////////////////////////////////////////////////////////////// // NativeMethods.IOleDocumentSite Implementation int NativeMethods.IOleDocumentSite.ActivateMe(NativeMethods.IOleDocumentView viewToActivate) { Debug.Assert(viewToActivate != null, "Expected the view to be non-null"); if (viewToActivate == null) { return(NativeMethods.E_INVALIDARG); } NativeMethods.COMRECT rect = new NativeMethods.COMRECT(); NativeMethods.GetClientRect(hostControl.Handle, rect); this.documentView = viewToActivate; this.documentView.SetInPlaceSite((NativeMethods.IOleInPlaceSite) this); this.documentView.UIActivate(1); this.documentView.SetRect(rect); this.documentView.Show(1); return(NativeMethods.S_OK); }
/////////////////////////////////////////////////////////////////////////// // IOleDocumentSite Implementation public virtual int ActivateMe(NativeMethods.IOleDocumentView pViewToActivate) { Debug.Assert(pViewToActivate != null, "Expected the view to be non-null"); if (pViewToActivate == null) { return(NativeMethods.E_INVALIDARG); } NativeMethods.COMRECT r = new NativeMethods.COMRECT(); NativeMethods.GetClientRect(parentControl.Handle, r); tridentView = pViewToActivate; tridentView.SetInPlaceSite((NativeMethods.IOleInPlaceSite) this); tridentView.UIActivate(1); tridentView.SetRect(r); tridentView.Show(1); return(NativeMethods.S_OK); }
/////////////////////////////////////////////////////////////////////////// // IOleDocumentSite Implementation public virtual int ActivateMe(NativeMethods.IOleDocumentView pViewToActivate) { Debug.WriteLineIf(StyleBuilder.StyleBuilderSwitch.TraceVerbose, "CTridentSite: IOleDocumentSite::ActivateMe"); Debug.Assert(pViewToActivate != null, "Expected the view to be non-null"); if (pViewToActivate == null) { return(NativeMethods.E_INVALIDARG); } //throw new COMException(String.Empty, NativeMethods.E_INVALIDARG); NativeMethods.COMRECT r = new NativeMethods.COMRECT(); NativeMethods.GetClientRect(parentControl.Handle, r); tridentView = pViewToActivate; tridentView.SetInPlaceSite((NativeMethods.IOleInPlaceSite) this); tridentView.UIActivate(1); tridentView.SetRect(r.ToWin32InteropCOMRECT()); tridentView.Show(1); return(NativeMethods.S_OK); }
/////////////////////////////////////////////////////////////////////////// // NativeMethods.IOleDocumentSite Implementation int NativeMethods.IOleDocumentSite.ActivateMe(NativeMethods.IOleDocumentView viewToActivate) { Debug.Assert(viewToActivate != null, "Expected the view to be non-null"); if (viewToActivate == null) { return NativeMethods.E_INVALIDARG; } NativeMethods.COMRECT rect = new NativeMethods.COMRECT(); NativeMethods.GetClientRect(hostControl.Handle, rect); this.documentView = viewToActivate; this.documentView.SetInPlaceSite((NativeMethods.IOleInPlaceSite) this); this.documentView.UIActivate(1); this.documentView.SetRect(rect); this.documentView.Show(1); return NativeMethods.S_OK; }
/////////////////////////////////////////////////////////////////////////// // IOleDocumentSite Implementation public virtual int ActivateMe(NativeMethods.IOleDocumentView pViewToActivate) { Debug.Assert(pViewToActivate != null, "Expected the view to be non-null"); if (pViewToActivate == null) return NativeMethods.E_INVALIDARG; NativeMethods.COMRECT r = new NativeMethods.COMRECT(); NativeMethods.GetClientRect(parentControl.Handle, r); tridentView = pViewToActivate; tridentView.SetInPlaceSite((NativeMethods.IOleInPlaceSite)this); tridentView.UIActivate(1); tridentView.SetRect(r); tridentView.Show(1); return NativeMethods.S_OK; }