IE编程——读取IE窗口信息

IE编程——读取IE窗口信息

目标:

         程序自动读取所有正在运行的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;
        }

    }
}
分类:  C&C++&C#&asp.net
0
0
(请您对文章做出评价)
« 上一篇: c# winform获取浏览器地址代码(收藏多种方式)
posted on  2013-04-14 10:18  萝卜皮 阅读( 193) 评论( 0编辑  收藏

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值