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()); } }
public void CreateHtml() { Debug.Assert(this.document == null, "Must call CloseHtml before recreating."); bool created = false; try { // create the trident instance this.document = (NativeMethods.IHTMLDocument2) new NativeMethods.HTMLDocument(); this.oleObject = (NativeMethods.IOleObject) this.document; // hand it our NativeMethods.IOleClientSite implementation this.oleObject.SetClientSite((NativeMethods.IOleClientSite) this); created = true; this.propertyNotifySinkCookie = new NativeMethods.ConnectionPointCookie(this.document, this, typeof(NativeMethods.IPropertyNotifySink), false); this.oleObject.Advise((NativeMethods.IAdviseSink) this, out adviseSinkCookie); Debug.Assert(adviseSinkCookie != 0); this.commandTarget = (NativeMethods.IOleCommandTarget) this.document; } finally { if (created == false) { this.document = null; this.oleObject = null; this.commandTarget = null; } } }
public virtual void GetOleVerbs(DesignerVerbCollection rval) { NativeMethods.IEnumOLEVERB verbEnum = null; NativeMethods.IOleObject obj = axHost.GetOcx() as NativeMethods.IOleObject; if (obj == null || NativeMethods.Failed(obj.EnumVerbs(out verbEnum))) { return; } Debug.Assert(verbEnum != null, "must have return value"); if (verbEnum == null) { return; } int[] fetched = new int[1]; NativeMethods.tagOLEVERB oleVerb = new NativeMethods.tagOLEVERB(); foundEdit = false; foundAbout = false; foundProperties = false; while (true) { fetched[0] = 0; oleVerb.lpszVerbName = null; int hr = verbEnum.Next(1, oleVerb, fetched); if (hr == NativeMethods.S_FALSE) { break; } else if (NativeMethods.Failed(hr)) { Debug.Fail("Failed to enumerate through enums: " + hr.ToString()); break; } // Believe it or not, some controls, notably the shdocview control, dont' return // S_FALSE and neither do they set fetched to 1. So, we need to comment out what's // below to maintain compatibility with Visual Basic. // if (fetched[0] != 1) { // Debug.fail("gotta have our 1 verb..."); // break; // } if ((oleVerb.grfAttribs & NativeMethods.ActiveX.OLEVERBATTRIB_ONCONTAINERMENU) != 0) { foundEdit = foundEdit || oleVerb.lVerb == OLEIVERB_UIACTIVATE; foundAbout = foundAbout || oleVerb.lVerb == HOSTVERB_ABOUT; foundProperties = foundProperties || oleVerb.lVerb == HOSTVERB_PROPERTIES; rval.Add(new HostVerb(new OleVerbData(oleVerb), handler)); } } }
/// <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()); } }
/////////////////////////////////////////////////////////////////////////// // Implementation /// <include file='doc\MSHTMLHost.uex' path='docs/doc[@for="TridentSite.CreateDocument"]/*' /> /// <devdoc> /// Creates a new instance of mshtml and initializes it as a new document /// using its IPersistStreamInit. /// </devdoc> protected void CreateDocument() { try { // Create an instance of Trident tridentDocument = (NativeMethods.IHTMLDocument2) new NativeMethods.HTMLDocument(); tridentOleObject = (NativeMethods.IOleObject)tridentDocument; // Initialize its client site tridentOleObject.SetClientSite((NativeMethods.IOleClientSite) this); // Initialize it NativeMethods.IPersistStreamInit psi = (NativeMethods.IPersistStreamInit)tridentDocument; psi.InitNew(); } catch (Exception e) { Debug.Fail(e.ToString()); throw e; } }
/// <include file='doc\MSHTMLHost.uex' path='docs/doc[@for="TridentSite.CreateDocument"]/*' /> /// <devdoc> /// Creates a new instance of mshtml and initializes it as a new document /// using its IPersistStreamInit. /// </devdoc> protected void CreateDocument() { Debug.WriteLineIf(StyleBuilder.StyleBuilderSwitch.TraceVerbose, "In TridentSite::CreateTrident"); try { // Create an instance of Trident tridentDocument = (Microsoft.VisualStudio.Interop.Trident.IHTMLDocument2) new HTMLDocument(); tridentOleObject = (NativeMethods.IOleObject)tridentDocument; // Initialize its client site Debug.WriteLineIf(StyleBuilder.StyleBuilderSwitch.TraceVerbose, "Setting Trident's IOleClientSite"); tridentOleObject.SetClientSite((NativeMethods.IOleClientSite) this); // Initialize it Debug.WriteLineIf(StyleBuilder.StyleBuilderSwitch.TraceVerbose, "Initializing Trident through IPersistStreamInit"); NativeMethods.IPersistStreamInit psi = (NativeMethods.IPersistStreamInit)tridentDocument; psi.InitNew(); } catch (Exception e) { Debug.Fail(e.ToString()); throw e; } }
public void CreateHtml() { Debug.Assert(this.document == null, "Must call CloseHtml before recreating."); bool created = false; try { // create the trident instance this.document = (NativeMethods.IHTMLDocument2) new NativeMethods.HTMLDocument(); this.oleObject = (NativeMethods.IOleObject) this.document; // hand it our NativeMethods.IOleClientSite implementation this.oleObject.SetClientSite((NativeMethods.IOleClientSite)this); created = true; this.propertyNotifySinkCookie = new NativeMethods.ConnectionPointCookie(this.document, this, typeof(NativeMethods.IPropertyNotifySink), false); this.oleObject.Advise((NativeMethods.IAdviseSink)this, out adviseSinkCookie); Debug.Assert(adviseSinkCookie != 0); this.commandTarget = (NativeMethods.IOleCommandTarget) this.document; } finally { if (created == false) { this.document = null; this.oleObject = null; this.commandTarget = null; } } }
/////////////////////////////////////////////////////////////////////////// // Implementation /// <include file='doc\MSHTMLHost.uex' path='docs/doc[@for="TridentSite.CreateDocument"]/*' /> /// <devdoc> /// Creates a new instance of mshtml and initializes it as a new document /// using its IPersistStreamInit. /// </devdoc> protected void CreateDocument() { try { // Create an instance of Trident tridentDocument = (NativeMethods.IHTMLDocument2)new NativeMethods.HTMLDocument(); tridentOleObject = (NativeMethods.IOleObject)tridentDocument; // Initialize its client site tridentOleObject.SetClientSite((NativeMethods.IOleClientSite)this); // Initialize it NativeMethods.IPersistStreamInit psi = (NativeMethods.IPersistStreamInit)tridentDocument; psi.InitNew(); } catch (Exception e) { Debug.Fail(e.ToString()); throw e; } }