コード例 #1
0
        /// <summary>
        /// Create Webbrowser control and set up it's events
        /// called from OnHandleCreated
        /// Webbrowser control hosting requires an HWND
        /// </summary>
        /// <returns></returns>
        private void InternalCreateWB()
        {
            //Create a new WB, throws exception if fails
            Type webbrowsertype = Type.GetTypeFromCLSID(Iid_Clsids.CLSID_WebBrowser, true);
            //Using Activator inplace of CoCreateInstance, returns IUnknown
            m_WBUnknown = System.Activator.CreateInstance(webbrowsertype);

            //Get the IOleObject
            m_WBOleObject = (IOleObject)m_WBUnknown;
            //Set client site
            int iret = m_WBOleObject.SetClientSite(this);
            //Set hostnames
            iret = m_WBOleObject.SetHostNames("csEXWB", string.Empty);

            //Get client rect
            bool brect = WinApis.GetClientRect(this.Handle, out m_WBRect);
            //Setup H+W
            m_WBRect.Right = m_WBRect.Right - m_WBRect.Left; //W
            m_WBRect.Bottom = m_WBRect.Bottom - m_WBRect.Top; //H
            m_WBRect.Left = 0;
            m_WBRect.Top = 0;

            //Get the IOleInPlaceObject
            m_WBOleInPlaceObject = (IOleInPlaceObject)m_WBUnknown;
            tagRECT trect = new tagRECT();
            WinApis.CopyRect(ref trect, ref m_WBRect);
            //Set WB rects
            iret = m_WBOleInPlaceObject.SetObjectRects(ref m_WBRect, ref trect);

            //INPLACEACTIVATE the WB
            iret = m_WBOleObject.DoVerb((int)OLEDOVERB.OLEIVERB_INPLACEACTIVATE, ref m_NullMsg, this, 0, this.Handle, ref m_WBRect);

            //Get the IWebBrowser2
            m_WBWebBrowser2 = (IWebBrowser2)m_WBUnknown;

            //By default, we handle dragdrops
            m_WBWebBrowser2.RegisterAsDropTarget = false;
            if (!DesignMode)
            {
                //Get connectionpointcontainer
                IConnectionPointContainer cpCont = (IConnectionPointContainer)m_WBUnknown;
                //Find connection point
                Guid guid = typeof(DWebBrowserEvents2).GUID;
                IConnectionPoint m_WBConnectionPoint = null;
                cpCont.FindConnectionPoint(ref guid, out m_WBConnectionPoint);
                //Advice
                m_WBConnectionPoint.Advise(this, out m_dwCookie);

                //Get the IOleComandTarget
                m_WBOleCommandTarget = (IOleCommandTarget)m_WBUnknown;

                //Reguster clipborad format for internal drag drop
                //RegisterClipboardFormatsForDragDrop();
            }

            if (!string.IsNullOrEmpty(m_sUrl))
                this.Navigate(m_sUrl);
            else
                this.Navigate("about:blank");

            //Get the shell embedding, ...
            WBIEServerHandle();
        }
コード例 #2
0
        protected override void Dispose(bool disposing)
        {
            if ((disposing) && (!this.DesignMode))
            {
                if (m_HookHandled != IntPtr.Zero)
                    Marshal.FreeHGlobal(m_HookHandled);
                if (m_WBThumbImg != null)
                    m_WBThumbImg.Dispose();
                InternalFreeWB();
                if ((components != null))
                    components.Dispose();

                // New Stuff
                m_WBWebBrowser2 = null;
                m_WBUnknown = null;
                m_WBOleObject = null;
                m_WBOleInPlaceObject = null;
                m_WBOleCommandTarget = null;

                RemoveDocumentChangeNotification();
                RemoveIUtilManEvents();
                RemCOMLibrary();

                // ParentWindow.onload should be nulled
                // the frames also
                //(IHTMLWindow2)doc2.parentWindow

                DocumentComplete = null;
                BeforeNavigate2 = null;
                ClientToHostWindow = null;
                CommandStateChange = null;
                DownloadBegin = null;
                DownloadComplete = null;
                FileDownload = null;
                NavigateComplete2 = null;
                NavigateError = null;
                NewWindow2 = null;
                NewWindow3 = null;
                PrintTemplateInstantiation = null;
                PrintTemplateTeardown = null;
                PrivacyImpactedStateChange = null;
                ProgressChange = null;
                PropertyChange = null;
                SetSecureLockIcon = null;
                StatusTextChange = null;
                TitleChange = null;
                WindowClosing = null;
                WindowSetHeight = null;
                WindowSetLeft = null;
                WindowSetResizable = null;
                WindowSetTop = null;
                WindowSetWidth = null;
                WBDragEnter = null;
                WBDragLeave = null;
                WBDragOver = null;
                WBDragDrop = null;
                WBKeyDown = null;
                WBKeyUp = null;
                WBContextMenu = null;
                WBGetOptionKeyPath = null;
                WBDocHostShowUIShowMessage = null;
                DocumentCompleteEX = null;
                WBAuthenticate = null;
                WBSecurityProblem = null;
                WBEvaluteNewWindow = null;
                ScriptError = null;
                UpdatePageStatus = null;
                RefreshBegin = null;
                RefreshEnd = null;
                ProcessUrlAction = null;
                AllowFocusChange = null;
                HTMLOMWindowServices_moveTo = null;
                HTMLOMWindowServices_moveBy = null;
                HTMLOMWindowServices_resizeTo = null;
                HTMLOMWindowServices_resizeBy = null;
                WBLButtonDown = null;
                WBLButtonUp = null;
                WBMouseMove = null;
                AuthenticationEvent = null;
            }
            base.Dispose(disposing);
        }