Пример #1
0
        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());
            }
        }
Пример #2
0
        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;
                }
            }
        }