C#读取IE窗口信息
2013-04-14 10:18
246 查看
IE编程——读取IE窗口信息
目标:
程序自动读取所有正在运行的IE(6.0或7.0)窗口信息,如窗口句柄HWND、状态文本StatusText、名字Name、路径Path等。
实现:
1. 添加对COM组件Microsoft Internet Controls的引用,如下图。
2. 获得IE窗口信息。
-收缩
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Data.OleDb;
namespace TestIWebBrowser
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
private void exitBtn_Click(object sender, EventArgs e)
{
this.Close();
}
private void explorerBtn_Click(object sender, EventArgs e)
{
resultTextBox.Text = TestSHDocVwDll.ReadExplorerInfo();
}
private void browserBtn_Click(object sender, EventArgs e)
{
resultTextBox.Text = TestSHDocVwDll.ReadIEInfo();
}
}
public class TestSHDocVwDll
{
public static string ReadIEInfo()
{
string strText = string.Empty;
SHDocVw.IShellWindows sw = new SHDocVw.ShellWindowsClass();
for (int i = 0; i < sw.Count; i++)
{
SHDocVw.IWebBrowser2 browser = sw.Item(i) as SHDocVw.IWebBrowser2;
if (browser != null && browser.FullName.ToUpper().IndexOf("IEXPLORE.EXE") > 0)
{
strText += "HWND : " + String.Format("{0:X}", browser.HWND) + "/r/n";
strText += "StatusText : " + browser.StatusText + "/r/n";
strText += "visible : " + browser.Visible.ToString() + "/r/n";
strText += "Name : " + browser.Name + "/r/n";
strText += "Path : " + browser.Path + "/r/n";
strText += "FullName : " + browser.FullName + "/r/n";
strText += "LocationName: " + browser.LocationName + "/r/n";
strText += "LocationURL : " + browser.LocationURL + "/r/n/r/n";
}
}
return strText;
}
public static string ReadExplorerInfo()
{
string strText = string.Empty;
SHDocVw.IShellWindows sw = new SHDocVw.ShellWindowsClass();
foreach (SHDocVw.InternetExplorer ie in sw)
{
//if it is windows explorer
if (ie.FullName.ToUpper().IndexOf("EXPLORER.EXE") > 0)
{
strText += "HWND : " + String.Format("{0:X}", ie.HWND) + "/r/n";
//strText += "StatusText : " + ie.StatusText + "/r/n";
strText += "visible : " + ie.Visible.ToString() + "/r/n";
strText += "Name : " + ie.Name + "/r/n";
strText += "Path : " + ie.Path + "/r/n";
strText += "FullName : " + ie.FullName + "/r/n";
strText += "LocationName: " + ie.LocationName + "/r/n";
strText += "LocationURL : " + ie.LocationURL + "/r/n/r/n";
}
}
//or coding as follows
//for (int i = 0; i < sw.Count; i++)
//{
// SHDocVw.InternetExplorer ie = sw.Item(i) as SHDocVw.InternetExplorer;
// //...
//}
return strText;
}
}
}
目标:
程序自动读取所有正在运行的IE(6.0或7.0)窗口信息,如窗口句柄HWND、状态文本StatusText、名字Name、路径Path等。
实现:
1. 添加对COM组件Microsoft Internet Controls的引用,如下图。
2. 获得IE窗口信息。
-收缩
C#代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Data.OleDb;
namespace TestIWebBrowser
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
private void exitBtn_Click(object sender, EventArgs e)
{
this.Close();
}
private void explorerBtn_Click(object sender, EventArgs e)
{
resultTextBox.Text = TestSHDocVwDll.ReadExplorerInfo();
}
private void browserBtn_Click(object sender, EventArgs e)
{
resultTextBox.Text = TestSHDocVwDll.ReadIEInfo();
}
}
public class TestSHDocVwDll
{
public static string ReadIEInfo()
{
string strText = string.Empty;
SHDocVw.IShellWindows sw = new SHDocVw.ShellWindowsClass();
for (int i = 0; i < sw.Count; i++)
{
SHDocVw.IWebBrowser2 browser = sw.Item(i) as SHDocVw.IWebBrowser2;
if (browser != null && browser.FullName.ToUpper().IndexOf("IEXPLORE.EXE") > 0)
{
strText += "HWND : " + String.Format("{0:X}", browser.HWND) + "/r/n";
strText += "StatusText : " + browser.StatusText + "/r/n";
strText += "visible : " + browser.Visible.ToString() + "/r/n";
strText += "Name : " + browser.Name + "/r/n";
strText += "Path : " + browser.Path + "/r/n";
strText += "FullName : " + browser.FullName + "/r/n";
strText += "LocationName: " + browser.LocationName + "/r/n";
strText += "LocationURL : " + browser.LocationURL + "/r/n/r/n";
}
}
return strText;
}
public static string ReadExplorerInfo()
{
string strText = string.Empty;
SHDocVw.IShellWindows sw = new SHDocVw.ShellWindowsClass();
foreach (SHDocVw.InternetExplorer ie in sw)
{
//if it is windows explorer
if (ie.FullName.ToUpper().IndexOf("EXPLORER.EXE") > 0)
{
strText += "HWND : " + String.Format("{0:X}", ie.HWND) + "/r/n";
//strText += "StatusText : " + ie.StatusText + "/r/n";
strText += "visible : " + ie.Visible.ToString() + "/r/n";
strText += "Name : " + ie.Name + "/r/n";
strText += "Path : " + ie.Path + "/r/n";
strText += "FullName : " + ie.FullName + "/r/n";
strText += "LocationName: " + ie.LocationName + "/r/n";
strText += "LocationURL : " + ie.LocationURL + "/r/n/r/n";
}
}
//or coding as follows
//for (int i = 0; i < sw.Count; i++)
//{
// SHDocVw.InternetExplorer ie = sw.Item(i) as SHDocVw.InternetExplorer;
// //...
//}
return strText;
}
}
}
相关文章推荐
- IE编程——读取IE窗口信息
- IE编程——读取IE窗口信息
- IE编程1(.net)——读取IE窗口信息
- C# 读取数据库信息
- 分享一个C#读取计算机信息的类
- C#实现Word中表格信息读取
- 打开新窗口及信息提示框(C#方法)
- C# 读取枚举描述信息实例
- 【转】C#关闭IE相应的窗口
- C# 窗口传递信息
- C#中三种弹出信息窗口的方式
- VS2005中用C#中的NameValueCollection类读取配置信息(转)
- asp.net c# web.config 读取web.config中自定义的参数信息,configuration section configSections
- C#读取IE的Cache
- C# 使用app.config文件方法 读取外部配置信息
- 编程乐趣:C#实现读取12306票价信息
- 用C#读取图片的EXIF信息的方法
- C#实现邮件发送,可以添加附件,发件人、收件人信息从xml文件读取
- 分享一个C#读取计算机信息的类
- C#中读取应用程序配置信息