示例#1
0
 public void AttachEvent(WebBrowser_V1 control, string handler)
 {
     switch (handler)
     {
     case WebView.OpenNewWindowEvent:
         control.NewWindow += WebBrowserV1_NewWindow;
         break;
     }
 }
        int IObjectWithSite.SetSite(object site)
        {
            this.site = site;
            try
            {
                if (site != null)
                {
                    var    serviceProv        = (IServiceProvider)this.site;
                    var    guidIWebBrowserApp = Marshal.GenerateGuidForType(typeof(IWebBrowserApp)); // new Guid("0002DF05-0000-0000-C000-000000000046");
                    var    guidIWebBrowser2   = Marshal.GenerateGuidForType(typeof(IWebBrowser2));   // new Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E");
                    IntPtr intPtr;
                    serviceProv.QueryService(ref guidIWebBrowserApp, ref guidIWebBrowser2, out intPtr);

                    browser = (IWebBrowser2)Marshal.GetObjectForIUnknown(intPtr);

                    ((DWebBrowserEvents2_Event)browser).DocumentComplete +=
                        new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
                    if (ieVersion >= 11)
                    {
                        ((DWebBrowserEvents2_Event)browser).BeforeNavigate2 +=
                            new DWebBrowserEvents2_BeforeNavigate2EventHandler(this.OnBeforeNavigate2);
                    }
                    else
                    {
                        axDocumentV1 = (WebBrowser_V1)browser;                                                                  // work-around
                        axDocumentV1.BeforeNavigate += new DWebBrowserEvents_BeforeNavigateEventHandler(this.OnBeforeNavigate); // work-around
                        //axDocumentV1.BeforeNavigate += this.OnBeforeNavigate;   // work-around
                    }
                }
                else
                {
                    ((DWebBrowserEvents2_Event)browser).DocumentComplete -=
                        new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
                    if (ieVersion >= 11)
                    {
                        ((DWebBrowserEvents2_Event)browser).BeforeNavigate2 -=
                            new DWebBrowserEvents2_BeforeNavigate2EventHandler(this.OnBeforeNavigate2);
                    }
                    else
                    {
                        axDocumentV1.BeforeNavigate -= new DWebBrowserEvents_BeforeNavigateEventHandler(this.OnBeforeNavigate);
                        //axDocumentV1.BeforeNavigate -= this.OnBeforeNavigate;
                    }
                    browser = null;
                }
            }
            catch (Exception ex)
            {
                log.WriteLog("exception occured:" + ex.ToString());
                MessageBox.Show("exception occured:" + ex.ToString());
            }
            //log.WriteLog("browser.LocationURL:" + browser.LocationURL);
            return(0);
        }
示例#3
0
        void f_form_Shown(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;
            //m_tab.Width = 999;

            // Set the WebBrowser to use an instance of the ScriptManager to handle method calls to C#.
            // wbMaster.ObjectForScripting = new ScriptManager(this);

            //var axWbMainV1 = (SHDocVw.WebBrowser_V1)wbMaster.ActiveXInstance;
            //var axWbSlaveV1 = (SHDocVw.WebBrowser_V1)wbSlave.ActiveXInstance;



            m_browser_ax = (SHDocVw.WebBrowser_V1)m_brow_web.ActiveXInstance;
            //m_browser.DocumentCompleted += (se, ev) =>
            //{
            //    if (m_browser.Document != null)
            //    {
            //        string url = m_browser.Url.ToString();
            //        m_tab_Browser.Text = m_browser.Document.Title;
            //        m_url_textBox.Text = url;
            //        m_browser_MessageLabel.Text = "Page loaded";
            //        log("DONE: " + url);

            //        m_browser_doc = m_browser_ax.Document as HTMLDocument;
            //        //DHTMLEventHandler eventHandler = new DHTMLEventHandler(docMain);
            //        //eventHandler.Handler += new DHTMLEvent(this.f_browser_document_onMouseOver);
            //        //((mshtml.DispHTMLDocument)docMain).onmouseover = eventHandler;
            //    }
            //};

            //// Use WebBrowser_V1 events as BeforeNavigate2 doesn't work with WPF WebBrowser
            //m_browser_ax.BeforeNavigate += (string URL, int Flags, string TargetFrameName, ref object PostData, string Headers, ref bool Cancel) =>
            //{
            //    //Cancel = true;
            //    //axWbMainV1.Stop();
            //    //axWbSlaveV1.Navigate(URL, Flags, TargetFrameName, PostData, Headers);
            //};

            //m_browser_ax.FrameBeforeNavigate += (string URL, int Flags, string TargetFrameName, ref object PostData, string Headers, ref bool Cancel) =>
            //{
            //    if (URL == "about:blank") return;

            //    log("FRAME GO: " + TargetFrameName + " = " + URL);
            //    Cancel = true;
            //    m_browser_ax.Stop();
            //    //axWbSlaveV1.Navigate(URL, Flags, TargetFrameName, PostData, Headers);
            //};



            //f_browser_google_MouseClick(null, null);
        }