如何控制IE的信息?

打开IE窗口后,在地址栏输入或者通过链接地址,如何通过监控获取到IE发送的地址?比如:在IE窗口的地址栏中输入:http://www.sina.com.cn 或者通过链接到 http://www.sina.com.cn ,监控程序里立即获取到 http://www.sina.com.cn 这个地址而做出相应的动作,请教,该如何来做?最好能给个实例!谢谢!
---------------------------------------------------------------
具体代码如下:

using System;
using System.Diagnostics ;
using System.Runtime.InteropServices;
using System.Collections;
using System.Net .Sockets ;
namespace fupip
{
public class geturl
{
public geturl()
{

}
[DllImport("user32.dll")]
public static extern int GetClassName(int hwnd, byte[] lpClassName,Int32[] nMaxCount);

[DllImport("user32.dll")]
public static extern int GetWindow(int hwnd,int wCmd);

[DllImport("user32.dll")]
public static extern int SendMessage(int hwnd,int wMsg,int wParam, byte[] lParam);

public const int GW_CHILD = 5;
public const int GW_HWNDNEXT = 2;
public const int WM_GETTEXT =13;
public const int WM_GETTEXTLENGTH = 14;

public static string[] GetIEURL(string args)
{

string[] urls;

Process[] ps =Process.GetProcessesByName(args);
urls=new string[ps.Length];
for(int i=0;i<ps.Length;i++)
{
int hwndIE=(int)ps[i].MainWindowHandle;

int hwndEdit=getkid(hwndIE);

urls[i]= gettext(hwndEdit);

}
return urls;
}

static int getkid(int hwnd)
{
byte[] str=new byte[100];
Int32[] len=new Int32[1];
int hwndkid=0;
string classname;
int handle=0;
len[0]=100;
ArrayList al=new ArrayList();

GetClassName(hwnd,str,len);
classname=System.Text.Encoding.ASCII.GetString(str);

if(classname.Substring(0,4)=="Edit")
{

handle= hwnd;
}

hwndkid=GetWindow(hwnd,GW_CHILD);

while(hwndkid!=0)
{
al.Add(hwndkid);
hwndkid=GetWindow(hwndkid,GW_HWNDNEXT);

}

foreach(int kid in al)
{
int i=getkid(kid);
if(i!=0)
handle=i;

}

return handle;

}
static string gettext(int hwnd)
{
int txtlen;
byte[] txt;
string text;
txtlen = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, new byte[]{0});

if(txtlen==0)
return "";
txt=new byte[txtlen+1];
txtlen = SendMessage(hwnd, WM_GETTEXT, txtlen+1, txt);

text=System.Text.Encoding.Default.GetString(txt);

return text;

}

}

}

Published At
Categories with Web编程
Tagged with
comments powered by Disqus