本博客(http://blog.csdn.net/livelylittlefish)贴出作者(三二一、小鱼)相关研究、学习内容所做的笔记,欢迎广大朋友指正!
IE编程——读取IE窗口信息
目标:
程序自动读取所有正在运行的IE(6.0或7.0)窗口信息,如窗口句柄HWND、状态文本StatusText、名字Name、路径Path等。
实现:
1. 添加对COM组件Microsoft Internet Controls的引用,如下图。
2. 获得IE窗口信息。
![](https://p-blog.csdn.net/images/p_blog_csdn_net/livelylittlefish/EntryImages/20080824/addMSHDocVw.dll.jpg)
- 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窗口如下:
![](https://p-blog.csdn.net/images/p_blog_csdn_net/livelylittlefish/EntryImages/20080824/IEInfo.JPG)
取得Windows资源浏览器的窗口如下:
![](https://p-blog.csdn.net/images/p_blog_csdn_net/livelylittlefish/EntryImages/20080824/ExplorerInfo.JPG)
本博客(http://blog.csdn.net/livelylittlefish)贴出作者(三二一、小鱼)相关研究、学习内容所做的笔记,欢迎广大朋友指正!
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窗口如下:
取得Windows资源浏览器的窗口如下:
IE编程2(.net)——通过应用程序打开google并进行搜索
通过应用程序操作google搜索,用户输入要搜索的内容,然后在google中搜索;若开始时并没有IE实例运行,则打开一个默认的IE。
1. 加入对Microsoft Internet Controls的引用;
2. 加入对Microsoft HTML Object Library的引用;
3. 通过mshtml.IHTMLDocument2、SHDocVw.InternetExplorer、SHDocVw.ShellWindowsClass获取当前打开的google搜索页面的IE窗口句柄;
4. 根据3返回的句柄,获得当前打开的google页面的mshtml.IHTMLDocument2对象;
5. 根据4返回的IHTMLDocument2对象,获得搜索输入框和提交按钮(可查看google页面源文件,确认输入框和提交按钮的类型和名字);
6. 在搜索输入框中输入要搜索的内容,并执行提交按钮的click动作即可进行搜索;
注:本文测试在中文系统下,若在其他语言系统下,需修改StatusText的判断。
几个对象和接口的简单解释:
1. ShellWindows Object
The ShellWindows object represents a collection of the open windows that belong to the Shell. Methods are provided that can be used to control and execute commands within the Shell. There are also methods that can be used to obtain other Shell-related objects.
2. InternetExplorer Object
Controls a remote instance of Microsoft Internet Explorer through Automation.
3. IHTMLDocument2 Interface
Stock Implementation: mshtml.dll
Inherits from: IDispatch interface
Header and IDL files: Mshtml.h, Mshtml.idl
This interface retrieves information about the document, and examines and modifies the HTML elements and text within the document.
Typically, every window object has a corresponding document object that you can retrieve by calling the QueryInterface method with the IID_IHTMLDocument or IID_IHTMLDocument2 interface identifiers. Windows that contain HTML documents always have valid document objects, but windows that contain documents in other formats might not.
4. IHTMLInputElement Interface
Stock Implementation: mshtml.dll
Inherits from: IDispatch interface
Header and IDL files: Mshtml.h, Mshtml.idl
This interface specifies any type of input control.
5. IHTMLElement Interface
Stock Implementation: mshtml.dll
Inherits from: IDispatch interface
Header and IDL files: Mshtml.h, Mshtml.idl
This interface provides the ability to programmatically access the properties and methods that are common to all element objects.
具体解释可参考msdn。
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- namespace TestAutoSearchInGoogle
- {
- public partial class FrmMain : Form
- {
- public FrmMain()
- {
- InitializeComponent();
- }
- private void exitBtn_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void searchBtn_Click(object sender, EventArgs e)
- {
- if(searchText.Text.Equals(""))
- {
- MessageBox.Show("please input the search text", "information prompt");
- return;
- }
- AutoSearchInGoogle.Search(searchText.Text);
- }
- }
- public class AutoSearchInGoogle
- {
- [DllImport("User32.dll", CharSet = CharSet.Auto)]
- public static extern int SetForegroundWindow(int hwnd);
- #region Search
- public static void Search(string searchText)
- {
- SHDocVw.InternetExplorer ieWnd = GetIEWndOfGoogle();
- mshtml.IHTMLDocument2 ieDoc = GetIEDocOfGoogle(ref ieWnd);
- System.Diagnostics.Trace.Assert(ieDoc != null);
- SearchTextInGoogle(ieDoc, searchText);
- //activate ie window
- SetForegroundWindow(ieWnd.HWND);
- }
- #endregion
- #region get ie window of google page
- public static SHDocVw.InternetExplorer GetIEWndOfGoogle()
- {
- mshtml.IHTMLDocument2 ieDoc;
- SHDocVw.InternetExplorer ieWnd = null;
- SHDocVw.ShellWindowsClass shellWindows = new SHDocVw.ShellWindowsClass();
- foreach (SHDocVw.InternetExplorer ie in shellWindows)
- {
- //if it is ie window
- if (ie.FullName.ToUpper().IndexOf("IEXPLORE.EXE") > 0)
- {
- //get the document displayed
- ieDoc = (mshtml.IHTMLDocument2)ie.Document;
- if (ieDoc.title.ToUpper().IndexOf("GOOGLE") >= 0)
- {
- ieWnd = ie;
- break;
- }
- }
- }
- shellWindows = null;
- return ieWnd;
- }
- #endregion
- #region get ie document of google page
- public static mshtml.IHTMLDocument2 GetIEDocOfGoogle(ref SHDocVw.InternetExplorer ieWnd)
- {
- object missing = null;
- mshtml.IHTMLDocument2 ieDoc;
- if (ieWnd == null)
- {
- ieWnd = new SHDocVw.InternetExplorer();
- ieWnd.Visible = true;
- ieWnd.Navigate("http://www.google.com", ref missing, ref missing, ref missing, ref missing);
- //wait for loading completed, or using DocumentComplete Event
- while (ieWnd.StatusText.IndexOf("完成") == -1)
- Application.DoEvents();
- }
- ieDoc = (mshtml.IHTMLDocument2)ieWnd.Document;
- return ieDoc;
- }
- #endregion
- #region Search the given text in google
- / <summary>
- /// search the given text in google home page
- /// we can see the source file of google home page to confirm the elements we need
- /// the html file of google home page is as follows
- ///
- /// <table cellpadding=0 cellspacing=0>
- /// <tr valign=top>
- /// <td width=25%> </td>
- /// <td align=center nowrap>
- /// <input name=hl type=hidden value=zh-CN>
- /// <input autocomplete="off" maxlength=2048 name=q size=55 title="Google 搜索" value="">
- /// <br>
- /// <input name=btnG type=submit value="Google 搜索">
- /// <input name=btnI type=submit value=" 手气不错 ">
- /// </td>
- /// ...
- / </summary>
- public static void SearchTextInGoogle(mshtml.IHTMLDocument2 ieDoc, string searchText)
- {
- mshtml.HTMLInputElementClass input;
- //set the text to be searched
- foreach (mshtml.IHTMLElement ieElement in ieDoc.all)
- {
- //if its tag is input and name is q(question)
- if (ieElement.tagName.ToUpper().Equals("INPUT"))
- {
- input = ((mshtml.HTMLInputElementClass)ieElement);
- if (input.name == "q")
- {
- input.value = searchText;
- break;
- }
- }
- }
- //click the submit button to search
- foreach (mshtml.IHTMLElement ieElement in ieDoc.all)
- {
- //if its tag is input
- if (ieElement.tagName.ToUpper().Equals("INPUT"))
- {
- input = (mshtml.HTMLInputElementClass)ieElement;
- if (input.name == "btnG")
- {
- input.click();
- break;
- }
- }
- }
- }
- #endregion
- }
- }
输入DirectUIHWND,搜索结果如下:
本博客(http://blog.csdn.net/livelylittlefish)贴出作者(三二一、小鱼)相关研究、学习内容所做的笔记,欢迎广大朋友指正!
IE编程——应用程序操作IE6
应用程序对IE6的操作分类:
1. 打开一个新的IE6窗口,并显示指定的页面;
2. 读取当前运行的所有IE6进程及其显示的页面url;
3. 读取指定的IE6窗口对应的IE6进程调用的模块及其线程;
4. 更新指定的IE6窗口url;
5. 关闭指定的IE6窗口;
将IE6操作封装为OperationOnIE6类,并将其用到的windows消息常量、windows API等也封装为类,分别为:ConstData、Win32API、CommonIEOperation,并指定这些类的命名空间为 AutoOperationOnIE6,具体可参考代码(AutoOperationOnIE6.cs文件)。
- using System;
- using System.Text;
- using Microsoft.Win32;
- using System.Threading;
- using System.Collections;
- using System.Diagnostics;
- using System.Runtime.InteropServices;
- namespace AutoOperationOnIE6
- {
- public class ConstData
- {
- #region define message
- public const int WM_SETTEXT = 0x000C; //set text
- public const int WM_GETTEXT = 0x000D; //get text
- public const int WM_KEYDOWN = 0x0100; //key down
- public const int WM_KEYUP = 0x0101; //key up
- public const int WM_ACTIVATE = 0x0006; //activate window
- public const int VK_RETURN = 0x0D; //key value of return
- #endregion
- }
- public class Win32API
- {
- #region api function
- [DllImport("User32.dll")]
- public static extern int FindWindowEx(int hwndParent, int hwndChildAfter, string lpszClass, string lpszWindow);
- [DllImport("User32.dll")]
- public static extern int SendMessage(int hWnd, int Msg, int wParam, StringBuilder lParam);
- [DllImport("User32.dll")]
- public static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);
- #endregion
- }
- public class CommonIEOperation
- {
- #region variable
- private static string defaultBrowserName; //default ie browser name
- private static string defaultBrowserPath; //default ie browser path
- #endregion
- #region Properties
- public static string DefaultBrowserName
- {
- get
- {
- return defaultBrowserName;
- }
- set
- {
- defaultBrowserName = value;
- }
- }
- public static string DefaultBrowserPath
- {
- get
- {
- return defaultBrowserPath;
- }
- set
- {
- defaultBrowserPath = value;
- }
- }
- #endregion
- #region get default browser
- public static void GetDefaultBrowser()
- {
- string strIE = string.Empty;
- string strIEExe = string.Empty;
- string[] strsegs;
- try
- {
- RegistryKey regKey = Registry.ClassesRoot;
- regKey = regKey.OpenSubKey(@"http/shell/open/command");
- strIE = regKey.GetValue("").ToString();
- strsegs = strIE.Split(new char[1] { '"' });
- foreach (string temp in strsegs)
- {
- if (temp.Contains(".exe") || temp.Contains(".EXE"))
- {
- strIEExe = temp.ToUpper();
- break;
- }
- }
- int startPos = strIEExe.LastIndexOf(@"/");
- int endPos = strIEExe.IndexOf(".EXE");
- if (endPos > startPos)
- {
- defaultBrowserName = strIEExe.Substring(startPos + 1, (endPos - startPos) - 1);
- }
- defaultBrowserPath = strIEExe.Substring(0, strIEExe.IndexOf(".EXE") + 4);
- }
- catch (Exception)
- {
- defaultBrowserName = string.Empty;
- defaultBrowserPath = string.Empty;
- }
- }
- #endregion
- #region get version of IE
- private static int GetIEVersion()
- {
- try
- {
- RegistryKey regKey = Registry.LocalMachine;
- regKey = regKey.OpenSubKey(@"SOFTWARE/Microsoft/Internet Explorer");
- string IEVersion = regKey.GetValue("Version").ToString();
- string strVersion = IEVersion.Substring(0, 1);
- return int.Parse(strVersion);
- }
- catch (Exception)
- {
- return 6;
- }
- }
- #endregion
- }
- public class OperationOnIE6
- {
- #region new a window with url
- public static Process NewUrl(string defaultIE,string url)
- {
- Process p = new Process();
- p.StartInfo.FileName = defaultIE;
- p.StartInfo.Arguments = url;
- p.Start();
- return p;
- }
- #endregion
- #region get url
- public static string GetUrl(int hIEWnd)
- {
- //using spy++ to find the type of window
- int hCtrlWnd = Win32API.FindWindowEx(hIEWnd, 0, "WorkerW", null);
- hCtrlWnd = Win32API.FindWindowEx(hCtrlWnd, 0, "ReBarWindow32", null);
- hCtrlWnd = Win32API.FindWindowEx(hCtrlWnd, 0, "ComboBoxEx32", null);
- hCtrlWnd = Win32API.FindWindowEx(hCtrlWnd, 0, "ComboBox", null);
- hCtrlWnd = Win32API.FindWindowEx(hCtrlWnd, 0, "Edit", null);
- StringBuilder buffer = new StringBuilder(1024);
- //send message to get url
- int num = Win32API.SendMessage(hCtrlWnd, ConstData.WM_GETTEXT, 1024, buffer);
- return buffer.ToString();
- }
- #endregion
- #region set url
- public static void SetUrl(int hIEWnd, StringBuilder strUrl)
- {
- //using spy++ to find the type of window
- int hCtrlWnd = Win32API.FindWindowEx(hIEWnd, 0, "WorkerW", null);
- hCtrlWnd = Win32API.FindWindowEx(hCtrlWnd, 0, "ReBarWindow32", null);
- hCtrlWnd = Win32API.FindWindowEx(hCtrlWnd, 0, "ComboBoxEx32", null);
- hCtrlWnd = Win32API.FindWindowEx(hCtrlWnd, 0, "ComboBox", null);
- int hUrlWnd = Win32API.FindWindowEx(hCtrlWnd, 0, "Edit", null);
- //set IE url
- Win32API.SendMessage(hUrlWnd, ConstData.WM_SETTEXT, 0, strUrl);
- //refresh IE
- Win32API.SendMessage(hUrlWnd, ConstData.WM_KEYDOWN, ConstData.VK_RETURN, null);
- //activate the window
- Win32API.SendMessage(hIEWnd, ConstData.WM_ACTIVATE, 0, null);
- }
- #endregion
- }
- }
编写应用程序,调用命名空间AutoOperationOnIE6的类。
- 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.Diagnostics;
- using System.Runtime.InteropServices;
- using AutoOperationOnIE6;
- namespace TestIE6Operation
- {
- public partial class FrmMain : Form
- {
- private ArrayList ie6Process = new ArrayList();
- public FrmMain()
- {
- InitializeComponent();
- }
- private void btnClose_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void btnClear_Click(object sender, EventArgs e)
- {
- urlList.Items.Clear();
- tbInfo.Clear();
- tbModules.Clear();
- tbThreads.Clear();
- ie6Process.Clear();
- tbUrl.Text = "about:blank";
- }
- private void btnGetUrl_Click(object sender, EventArgs e)
- {
- ie6Process.Clear();
- urlList.Items.Clear();
- Process[] process = Process.GetProcessesByName("IEXPLORE");
- foreach (Process curie in process)
- {
- IntPtr ieHandle = curie.MainWindowHandle;
- string strurl = OperationOnIE6.GetUrl(ieHandle.ToInt32());
- ie6Process.Add(curie);
- urlList.Items.Add(strurl);
- }
- }
- private void urlList_MouseDoubleClick(object sender, MouseEventArgs e)
- {
- if (urlList.Items.Count==0)
- return;
- int index = urlList.SelectedIndex;
- Process curprocess = (Process)ie6Process[index];
- string strinfo = string.Empty;
- strinfo += "machine name : " + curprocess.MachineName + "/r/n";
- strinfo += "main module : " + curprocess.MainModule.ToString() + "/r/n";
- strinfo += "process id : " + curprocess.Id.ToString() + "/r/n";
- strinfo += "window handle: " + curprocess.MainWindowHandle.ToString() + "/r/n";
- strinfo += "window title : " + curprocess.MainWindowTitle;
- tbInfo.Text = strinfo;
- strinfo = string.Empty;
- ProcessModuleCollection modules = curprocess.Modules;
- for (int i = 0; i < modules.Count;i++ )
- {
- strinfo += "module Name : " + modules[i].ModuleName + "/r/n";
- strinfo += "file Name : " + modules[i].FileName + "/r/n";
- strinfo += "file Version: " + modules[i].FileVersionInfo.FileVersion + "/r/n";
- strinfo += "company name: " + modules[i].FileVersionInfo.CompanyName + "/r/n";
- strinfo += "comments : " + modules[i].FileVersionInfo.Comments + "/r/n/r/n";
- }
- tbModules.Text = strinfo;
- strinfo = string.Empty;
- ProcessThreadCollection threads = curprocess.Threads;
- for (int i = 0; i < threads.Count; i++)
- {
- strinfo += "thread id : " + threads[i].Id + "/r/n";
- strinfo += "os kernel : " + threads[i].PrivilegedProcessorTime.ToString() + "/r/n";
- strinfo += "start time: " + threads[i].StartTime+ "/r/n";
- strinfo += "total time: " + threads[i].TotalProcessorTime.ToString() + "/r/n";
- strinfo += "user time : " + threads[i].UserProcessorTime+ "/r/n/r/n";
- }
- tbThreads.Text = strinfo;
- }
- private void btnNewUrl_Click(object sender, EventArgs e)
- {
- if(tbUrl.Text==string.Empty)
- {
- MessageBox.Show("please input a url", "prompt information", MessageBoxButtons.OK, MessageBoxIcon.Information);
- tbUrl.Focus();
- return;
- }
- CommonIEOperation.GetDefaultBrowser();
- Process p = OperationOnIE6.NewUrl(CommonIEOperation.DefaultBrowserPath, tbUrl.Text);
- urlList.Items.Add(tbUrl.Text);
- ie6Process.Add(p);
- }
- private void btnSetUrl_Click(object sender, EventArgs e)
- {
- if (urlList.Items.Count == 0)
- return;
- if(urlList.SelectedIndex<0)
- {
- MessageBox.Show("please select a url", "prompt information", MessageBoxButtons.OK, MessageBoxIcon.Information);
- urlList.Focus();
- return;
- }
- if (tbUrl.Text == string.Empty)
- {
- MessageBox.Show("please input a url", "prompt information", MessageBoxButtons.OK, MessageBoxIcon.Information);
- tbUrl.Focus();
- return;
- }
- int index = urlList.SelectedIndex;
- int hIEWnd=((Process)ie6Process[index]).MainWindowHandle.ToInt32();
- StringBuilder strUrl = new StringBuilder();
- strUrl.Append(tbUrl.Text);
- OperationOnIE6.SetUrl(hIEWnd, strUrl);
- urlList.Items[index] = strUrl;
- }
- private void btnDelete_Click(object sender, EventArgs e)
- {
- if (urlList.Items.Count > 0)
- {
- if (urlList.SelectedIndex < 0)
- {
- MessageBox.Show("please select a url", "prompt information", MessageBoxButtons.OK, MessageBoxIcon.Information);
- urlList.Focus();
- return;
- }
- int index = urlList.SelectedIndex;
- ((Process)ie6Process[index]).Kill();
- ie6Process.RemoveAt(index);
- urlList.Items.RemoveAt(index);
- if (index > 0)
- urlList.SelectedIndex = index - 1;
- else
- {
- if (urlList.Items.Count > 0)
- urlList.SelectedIndex = 0;
- else
- urlList.SelectedIndex = -1;
- }
- }
- }
- }
- }
运行结果如下: