how to connect to an open window of internet explorer using c#?

こ雲淡風輕ζ 提交于 2019-12-05 19:01:57
Evan

I found the answer here and the code excerpt is:

public class Form1 : System.Windows.Forms.Form
{
    static private SHDocVw.ShellWindows shellWindows = new
    SHDocVw.ShellWindowsClass();

    public Form1()
    {
       InitializeComponent();    
       foreach(SHDocVw.InternetExplorer ie in shellWindows)
       {
           MessageBox.Show("ie.Location:" + ie.LocationURL);
           ie.BeforeNavigate2 += new
           SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(this.ie_BeforeNavigate2);
       }
}

 public void ie_BeforeNavigate2(object pDisp , ref object url, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel)
 {
  MessageBox.Show("event received!");
 } 
}

Anyone know if the code on that webpage would also work with IE 6? I tested it on 7. Thanks!

Manisha Mehta shows on http://www.codeproject.com/KB/cs/runninginstanceie.aspx how to do this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!