Пример #1
0
        public virtual void Release()
        {
            canvasHWND = IntPtr.Zero;
            mainHWND   = IntPtr.Zero;

            if (m_pDWebBrowserEvents2 != null)
            {
                Marshal.ReleaseComObject(m_pDWebBrowserEvents2);
                m_pDWebBrowserEvents2 = null;
            }

            if (m_pIWebBrowser2 != null)
            {
                Marshal.ReleaseComObject(m_pIWebBrowser2);
                m_pIWebBrowser2 = null;
            }
        }
Пример #2
0
        public SetSiteResults SetSiteWithStatus(object pUnkSite)
        {
            if (m_pIWebBrowser2 != null)
            {
                Release();
            }

            if (pUnkSite == null)
            {
                return(SetSiteResults.NoSite);
            }

            try
            {
                MySpace.MSFast.SysImpl.Win32.ComIterop.IServiceProvider pSp = pUnkSite as MySpace.MSFast.SysImpl.Win32.ComIterop.IServiceProvider;

                if (pSp == null)
                {
                    Release();
                    return(SetSiteResults.SiteIsNotServiceProvider);
                }

                IntPtr ipWb2 = IntPtr.Zero;

                pSp.QueryService(ref IID_IWebBrowserApp, ref IID_IWebBrowser2, out ipWb2);

                if (ipWb2 == IntPtr.Zero)
                {
                    Marshal.Release(ipWb2);
                    Release();
                    return(SetSiteResults.SiteIsNotAWebBrowser);
                }

                m_pIWebBrowser2 = Marshal.GetObjectForIUnknown(ipWb2) as IWebBrowser2;
                Marshal.Release(ipWb2);

                if (m_pIWebBrowser2 == null)
                {
                    Release();
                    return(SetSiteResults.SiteIsNotAWebBrowser);
                }

                string sHostName = m_pIWebBrowser2.FullName;

                if (sHostName == null)
                {
                    Release();
                    return(SetSiteResults.SiteHasNoName);
                }

                if (!(sHostName.ToUpper().EndsWith("IEXPLORE.EXE")))
                {
                    Release();
                    return(SetSiteResults.SiteIsNotIExplorer);
                }

                m_pDWebBrowserEvents2 = m_pIWebBrowser2 as SHDocVw.DWebBrowserEvents2_Event;

                this.mainHWND = (IntPtr)m_pIWebBrowser2.HWND;

                if (m_pDWebBrowserEvents2 == null)
                {
                    Release();
                    return(SetSiteResults.CantRegisterEventHandlers);
                }

                m_pDWebBrowserEvents2.BeforeNavigate2   += new SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(this.OnBeforeNavigate);
                m_pDWebBrowserEvents2.DocumentComplete  += new SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
                m_pDWebBrowserEvents2.OnQuit            += new SHDocVw.DWebBrowserEvents2_OnQuitEventHandler(this.OnQuit);
                m_pDWebBrowserEvents2.NavigateComplete2 += new DWebBrowserEvents2_NavigateComplete2EventHandler(this.NavigateComplete2);
            }
            catch
            {
                Release();
                return(SetSiteResults.UnknownException);
            }

            CheckPageReady();

            return(SetSiteResults.Success);
        }