如何连接到使用c#的Internet Explorer的打开窗口? [英] how to connect to an open window of internet explorer using c#?
本文介绍了如何连接到使用c#的Internet Explorer的打开窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您可以在C#程序中使用COM / OLE连接到正在运行的Internet Explorer实例吗?
理想情况下,我想查找所有网页的网址 answer / 106526-automating-external-instances-internet-explorer-crel =nofollow noreferrer>此处,代码摘录为:
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!);
}
}
任何人知道该网页上的代码是否也能工作与IE 6?我测试了它7.谢谢!
Can you use COM/OLE in a C# program to connect to a running instances of internet explorer?
Ideally I'd like to find the URLs of all webpages open in IE.
解决方案
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!
这篇关于如何连接到使用c#的Internet Explorer的打开窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文