/// <summary> /// This method is called when the BHO is instantiated and when /// it is destroyed. The site is an object implemented the /// interface InternetExplorer. /// </summary> /// <param name="site"></param> public int SetSite(Object site) { // Release previous COM objects. if (this.ieInstance != null) { Marshal.ReleaseComObject(this.ieInstance); this.ieInstance = null; } // The site implements IServiceProvider interface and can be used to // get InternetExplorer instance. var provider = site as BHO.IServiceProvider; if (provider != null) { Guid guid = new Guid("{0002DF05-0000-0000-C000-000000000046}"); Guid riid = new Guid("{00000000-0000-0000-C000-000000000046}"); try { object webBrowser; provider.QueryService(ref guid, ref riid, out webBrowser); this.ieInstance = webBrowser as InternetExplorer; } catch (COMException) { } } if (site != null) { webBrowser = site as WebBrowser; if (webBrowser != null) { // Register the DocumentComplete event. axDocumentV1 = (WebBrowser_V1)site; axDocumentV1.BeforeNavigate += axDocumentV1_BeforeNavigate; //ieInstance.NavigateComplete2 += new DWebBrowserEvents2_NavigateComplete2EventHandler(webBrowser_NavigateComplete2); webBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(webBrowser_DocumentComplete); } } else { if (webBrowser != null) { axDocumentV1 = (WebBrowser_V1)site; axDocumentV1.BeforeNavigate -= axDocumentV1_BeforeNavigate; //ieInstance.NavigateComplete2 += new DWebBrowserEvents2_NavigateComplete2EventHandler(webBrowser_NavigateComplete2); webBrowser.DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(webBrowser_DocumentComplete); webBrowser = null; } } return(0); }
private void f_form_Shown(object sender, EventArgs e) { this.WindowState = FormWindowState.Maximized; txt_Log.Width = this.Width / 2; // Ensure that ScriptErrorsSuppressed is set to false. wbMaster.ScriptErrorsSuppressed = browser_run_debug_mode ? false : true; // 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; axWbMainV1 = (SHDocVw.WebBrowser_V1)wbMaster.ActiveXInstance; axWbSlaveV1 = (SHDocVw.WebBrowser_V1)wbSlave.ActiveXInstance; //axWbMainV1.DownloadComplete += f_axWbMainV1__DownloadComplete; ////manualNavigation = false; ////// Use WebBrowser_V1 events as BeforeNavigate2 doesn't work with WPF WebBrowser ////axWbMainV1.BeforeNavigate += (string URL, int Flags, string TargetFrameName, ref object PostData, string Headers, ref bool Cancel) => ////{ //// if (!manualNavigation) //// return; //// Cancel = true; //// axWbMainV1.Stop(); //// axWbSlaveV1.Navigate(URL, Flags, TargetFrameName, PostData, Headers); ////}; ////axWbMainV1.FrameBeforeNavigate += (string URL, int Flags, string TargetFrameName, ref object PostData, string Headers, ref bool Cancel) => ////{ //// if (!manualNavigation) //// return; //// Cancel = true; //// axWbMainV1.Stop(); //// axWbSlaveV1.Navigate(URL, Flags, TargetFrameName, PostData, Headers); ////}; ////axWbMainV1.NavigateComplete += (string URL) => ////{ //// manualNavigation = true; //// txt_Log.Text += Environment.NewLine + Environment.NewLine + "=====> axWbMainV1.NavigateComplete"; ////}; ////axWbMainV1.FrameNavigateComplete += (string URL) => ////{ //// manualNavigation = true; ////}; ////axWbMainV1.NewWindow += (string URL, int Flags, string TargetFrameName, ref object PostData, string Headers, ref bool Processed) => ////{ //// if (!manualNavigation) //// return; //// Processed = true; //// axWbMainV1.Stop(); //// axWbSlaveV1.Navigate(URL, Flags, String.Empty, PostData, Headers); ////}; ////manualNavigation = false; //////axWbMainV1.Navigate(url); //wbMaster.Navigate("about:blank"); f_web_loadHTML(); }