网页编程终级——操作ie浏览器及实例

IE编程1(.net)——读取IE窗口信息

分类: .net研究 932人阅读 评论(2) 收藏 举报

本博客(http://blog.csdn.net/livelylittlefish)贴出作者(三二一、小鱼)相关研究、学习内容所做的笔记,欢迎广大朋友指正!

 

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

 

目标:

         程序自动读取所有正在运行的IE(6.0或7.0)窗口信息,如窗口句柄HWND、状态文本StatusText、名字Name、路径Path等。

 

实现:

        1. 添加对COM组件Microsoft Internet Controls的引用,如下图。

        2. 获得IE窗口信息。                                     

 

           

                                       

[c-sharp] view plain copy print ?
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8.   
  9. using System.Collections;  
  10. using System.Data.OleDb;  
  11.   
  12. namespace TestIWebBrowser  
  13. {  
  14.     public partial class frmMain : Form  
  15.     {  
  16.         public frmMain()  
  17.         {  
  18.             InitializeComponent();  
  19.         }  
  20.   
  21.         private void exitBtn_Click(object sender, EventArgs e)  
  22.         {  
  23.             this.Close();  
  24.         }  
  25.   
  26.         private void explorerBtn_Click(object sender, EventArgs e)  
  27.         {  
  28.             resultTextBox.Text = TestSHDocVwDll.ReadExplorerInfo();  
  29.         }  
  30.   
  31.         private void browserBtn_Click(object sender, EventArgs e)  
  32.         {  
  33.             resultTextBox.Text = TestSHDocVwDll.ReadIEInfo();  
  34.         }  
  35.     }  
  36.   
  37.     public class TestSHDocVwDll  
  38.     {  
  39.         public static string ReadIEInfo()  
  40.         {  
  41.             string strText = string.Empty;  
  42.               
  43.             SHDocVw.IShellWindows sw = new SHDocVw.ShellWindowsClass();  
  44.             for (int i = 0; i < sw.Count; i++)  
  45.             {  
  46.                 SHDocVw.IWebBrowser2 browser = sw.Item(i) as SHDocVw.IWebBrowser2;  
  47.   
  48.                 if (browser != null && browser.FullName.ToUpper().IndexOf("IEXPLORE.EXE") > 0)  
  49.                 {  
  50.                     strText += "HWND        : " + String.Format("{0:X}", browser.HWND) + "/r/n";  
  51.                     strText += "StatusText  : " + browser.StatusText + "/r/n";  
  52.                     strText += "visible     : " + browser.Visible.ToString() + "/r/n";  
  53.                     strText += "Name        : " + browser.Name + "/r/n";  
  54.                     strText += "Path        : " + browser.Path + "/r/n";  
  55.                     strText += "FullName    : " + browser.FullName + "/r/n";  
  56.                     strText += "LocationName: " + browser.LocationName + "/r/n";  
  57.                     strText += "LocationURL : " + browser.LocationURL + "/r/n/r/n";                      
  58.                 }  
  59.             }  
  60.   
  61.             return strText;  
  62.         }  
  63.   
  64.         public static string ReadExplorerInfo()  
  65.         {  
  66.             string strText = string.Empty;  
  67.   
  68.             SHDocVw.IShellWindows sw = new SHDocVw.ShellWindowsClass();  
  69.             foreach (SHDocVw.InternetExplorer ie in sw)  
  70.             {  
  71.                 //if it is windows explorer   
  72.                 if (ie.FullName.ToUpper().IndexOf("EXPLORER.EXE") > 0)  
  73.                 {  
  74.                     strText += "HWND        : " + String.Format("{0:X}", ie.HWND) + "/r/n";  
  75.                     //strText += "StatusText  : " + ie.StatusText + "/r/n";   
  76.                     strText += "visible     : " + ie.Visible.ToString() + "/r/n";  
  77.                     strText += "Name        : " + ie.Name + "/r/n";  
  78.                     strText += "Path        : " + ie.Path + "/r/n";  
  79.                     strText += "FullName    : " + ie.FullName + "/r/n";  
  80.                     strText += "LocationName: " + ie.LocationName + "/r/n";  
  81.                     strText += "LocationURL : " + ie.LocationURL + "/r/n/r/n";  
  82.                 }  
  83.             }  
  84.   
  85.             //or coding as follows   
  86.             //for (int i = 0; i < sw.Count; i++)   
  87.             //{                   
  88.             //    SHDocVw.InternetExplorer ie = sw.Item(i) as SHDocVw.InternetExplorer;   
  89.             //    //...   
  90.             //}   
  91.   
  92.             return strText;  
  93.         }  
  94.   
  95.     }  
  96. }  
 

 

取得的IE窗口如下:

                                  

        取得Windows资源浏览器的窗口如下:

 

 

IE编程2(.net)——通过应用程序打开google并进行搜索

IE编程——通过应用程序打开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。

 

[c-sharp] view plain copy print ?
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8.   
  9. using System.Runtime.InteropServices;  
  10.   
  11. namespace TestAutoSearchInGoogle  
  12. {  
  13.     public partial class FrmMain : Form  
  14.     {  
  15.         public FrmMain()  
  16.         {  
  17.             InitializeComponent();  
  18.         }  
  19.   
  20.         private void exitBtn_Click(object sender, EventArgs e)  
  21.         {  
  22.             this.Close();  
  23.         }  
  24.   
  25.         private void searchBtn_Click(object sender, EventArgs e)  
  26.         {  
  27.             if(searchText.Text.Equals(""))  
  28.             {  
  29.                 MessageBox.Show("please input the search text""information prompt");  
  30.                 return;  
  31.             }  
  32.             AutoSearchInGoogle.Search(searchText.Text);  
  33.         }  
  34.     }  
  35.   
  36.     public class AutoSearchInGoogle  
  37.     {  
  38.         [DllImport("User32.dll", CharSet = CharSet.Auto)]  
  39.         public static extern int SetForegroundWindow(int hwnd);   
  40.  
  41.         #region Search   
  42.         public static void Search(string searchText)  
  43.         {  
  44.             SHDocVw.InternetExplorer ieWnd = GetIEWndOfGoogle();  
  45.             mshtml.IHTMLDocument2 ieDoc = GetIEDocOfGoogle(ref ieWnd);  
  46.   
  47.             System.Diagnostics.Trace.Assert(ieDoc != null);  
  48.             SearchTextInGoogle(ieDoc, searchText);  
  49.   
  50.             //activate ie window   
  51.             SetForegroundWindow(ieWnd.HWND);              
  52.         }   
  53.         #endregion   
  54.  
  55.         #region get ie window of google page   
  56.         public static SHDocVw.InternetExplorer GetIEWndOfGoogle()  
  57.         {  
  58.             mshtml.IHTMLDocument2 ieDoc;  
  59.             SHDocVw.InternetExplorer ieWnd = null;  
  60.             SHDocVw.ShellWindowsClass shellWindows = new SHDocVw.ShellWindowsClass();  
  61.   
  62.             foreach (SHDocVw.InternetExplorer ie in shellWindows)  
  63.             {  
  64.                 //if it is ie window   
  65.                 if (ie.FullName.ToUpper().IndexOf("IEXPLORE.EXE") > 0)  
  66.                 {  
  67.                     //get the document displayed   
  68.                     ieDoc = (mshtml.IHTMLDocument2)ie.Document;  
  69.                     if (ieDoc.title.ToUpper().IndexOf("GOOGLE") >= 0)  
  70.                     {  
  71.                         ieWnd = ie;  
  72.                         break;  
  73.                     }  
  74.                 }  
  75.             }  
  76.               
  77.             shellWindows = null;  
  78.   
  79.             return ieWnd;  
  80.         }   
  81.         #endregion   
  82.  
  83.         #region get ie document of google page   
  84.         public static mshtml.IHTMLDocument2 GetIEDocOfGoogle(ref SHDocVw.InternetExplorer ieWnd)  
  85.         {  
  86.             object missing = null;  
  87.             mshtml.IHTMLDocument2 ieDoc;  
  88.   
  89.             if (ieWnd == null)  
  90.             {  
  91.                 ieWnd = new SHDocVw.InternetExplorer();  
  92.                 ieWnd.Visible = true;  
  93.                 ieWnd.Navigate("http://www.google.com"ref missing, ref missing, ref missing, ref missing);  
  94.   
  95.                 //wait for loading completed, or using DocumentComplete Event   
  96.                 while (ieWnd.StatusText.IndexOf("完成") == -1)  
  97.                     Application.DoEvents();  
  98.             }  
  99.   
  100.             ieDoc = (mshtml.IHTMLDocument2)ieWnd.Document;  
  101.             return ieDoc;  
  102.         }   
  103.         #endregion   
  104.  
  105.         #region Search the given text in google   
  106.         / <summary>   
  107.         /// search the given text in google home page   
  108.         /// we can see the source file of google home page to confirm the elements we need   
  109.         /// the html file of google home page is as follows   
  110.         ///    
  111.         /// <table cellpadding=0 cellspacing=0>   
  112.         ///     <tr valign=top>   
  113.         ///         <td width=25%> </td>   
  114.         ///         <td align=center nowrap>   
  115.         ///             <input name=hl type=hidden value=zh-CN>   
  116.         ///             <input autocomplete="off" maxlength=2048 name=q size=55 title="Google 搜索" value="">   
  117.         ///             <br>   
  118.         ///             <input name=btnG type=submit value="Google 搜索">   
  119.         ///             <input name=btnI type=submit value=" 手气不错 ">   
  120.         ///         </td>   
  121.         ///         ...   
  122.         / </summary>           
  123.         public static void SearchTextInGoogle(mshtml.IHTMLDocument2 ieDoc, string searchText)  
  124.         {  
  125.             mshtml.HTMLInputElementClass input;  
  126.   
  127.             //set the text to be searched   
  128.             foreach (mshtml.IHTMLElement ieElement in ieDoc.all)  
  129.             {  
  130.                 //if its tag is input and name is q(question)   
  131.                 if (ieElement.tagName.ToUpper().Equals("INPUT"))  
  132.                 {  
  133.                     input = ((mshtml.HTMLInputElementClass)ieElement);  
  134.                     if (input.name == "q")  
  135.                     {  
  136.                         input.value = searchText;  
  137.                         break;  
  138.                     }  
  139.                 }  
  140.             }  
  141.   
  142.             //click the submit button to search   
  143.             foreach (mshtml.IHTMLElement ieElement in ieDoc.all)  
  144.             {  
  145.                 //if its tag is input   
  146.                 if (ieElement.tagName.ToUpper().Equals("INPUT"))  
  147.                 {  
  148.                     input = (mshtml.HTMLInputElementClass)ieElement;  
  149.                     if (input.name == "btnG")  
  150.                     {  
  151.                         input.click();  
  152.                         break;  
  153.                     }  
  154.                 }  
  155.             }  
  156.         }   
  157.         #endregion   
  158.     }  
  159. }  

输入DirectUIHWND,搜索结果如下:

 

 

IE编程3(.net)——应用程序操作IE6

分类: .net研究 707人阅读 评论(0) 收藏 举报

本博客(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文件)。

[c-sharp] view plain copy print ?
  1. using System;  
  2. using System.Text;  
  3. using Microsoft.Win32;  
  4. using System.Threading;  
  5. using System.Collections;  
  6. using System.Diagnostics;  
  7. using System.Runtime.InteropServices;  
  8.   
  9. namespace AutoOperationOnIE6  
  10. {  
  11.     public class ConstData  
  12.     {  
  13.         #region define message  
  14.         public const int WM_SETTEXT = 0x000C;  //set text  
  15.         public const int WM_GETTEXT = 0x000D;  //get text  
  16.         public const int WM_KEYDOWN = 0x0100;  //key down  
  17.         public const int WM_KEYUP = 0x0101;       //key up  
  18.         public const int WM_ACTIVATE = 0x0006;  //activate window  
  19.   
  20.         public const int VK_RETURN = 0x0D;     //key value of return  
  21.         #endregion  
  22.     }  
  23.   
  24.     public class Win32API  
  25.     {  
  26.         #region api function  
  27.         [DllImport("User32.dll")]  
  28.         public static extern int FindWindowEx(int hwndParent, int hwndChildAfter, string lpszClass, string lpszWindow);  
  29.   
  30.   
  31.         [DllImport("User32.dll")]  
  32.         public static extern int SendMessage(int hWnd, int Msg, int wParam, StringBuilder lParam);  
  33.   
  34.         [DllImport("User32.dll")]  
  35.         public static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);  
  36.         #endregion  
  37.     }  
  38.   
  39.     public class CommonIEOperation  
  40.     {  
  41.         #region variable  
  42.         private static string defaultBrowserName;  //default ie browser name  
  43.         private static string defaultBrowserPath;  //default ie browser path  
  44.         #endregion  
  45.  
  46.         #region Properties  
  47.         public static string DefaultBrowserName  
  48.         {  
  49.             get   
  50.             {   
  51.                 return defaultBrowserName;   
  52.             }  
  53.             set  
  54.             {  
  55.                 defaultBrowserName = value;  
  56.             }  
  57.         }  
  58.   
  59.         public static string DefaultBrowserPath  
  60.         {  
  61.             get  
  62.             {  
  63.                 return defaultBrowserPath;  
  64.             }  
  65.             set  
  66.             {  
  67.                 defaultBrowserPath = value;  
  68.             }  
  69.         }  
  70.         #endregion  
  71.  
  72.         #region get default browser  
  73.         public static void GetDefaultBrowser()  
  74.         {  
  75.             string strIE = string.Empty;  
  76.             string strIEExe = string.Empty;  
  77.             string[] strsegs;  
  78.             try  
  79.             {  
  80.                 RegistryKey regKey = Registry.ClassesRoot;  
  81.                 regKey = regKey.OpenSubKey(@"http/shell/open/command");  
  82.                 strIE = regKey.GetValue("").ToString();  
  83.   
  84.                 strsegs = strIE.Split(new char[1] { '"' });  
  85.                 foreach (string temp in strsegs)  
  86.                 {  
  87.                     if (temp.Contains(".exe") || temp.Contains(".EXE"))  
  88.                     {  
  89.                         strIEExe = temp.ToUpper();  
  90.                         break;  
  91.                     }  
  92.                 }  
  93.   
  94.                 int startPos = strIEExe.LastIndexOf(@"/");  
  95.                 int endPos = strIEExe.IndexOf(".EXE");  
  96.                 if (endPos > startPos)  
  97.                 {  
  98.                     defaultBrowserName = strIEExe.Substring(startPos + 1, (endPos - startPos) - 1);  
  99.                 }  
  100.   
  101.                 defaultBrowserPath = strIEExe.Substring(0, strIEExe.IndexOf(".EXE") + 4);  
  102.             }  
  103.             catch (Exception)  
  104.             {  
  105.                 defaultBrowserName = string.Empty;  
  106.                 defaultBrowserPath = string.Empty;  
  107.             }  
  108.         }  
  109.         #endregion  
  110.  
  111.         #region get version of IE  
  112.         private static int GetIEVersion()  
  113.         {  
  114.             try  
  115.             {  
  116.                 RegistryKey regKey = Registry.LocalMachine;  
  117.                 regKey = regKey.OpenSubKey(@"SOFTWARE/Microsoft/Internet Explorer");  
  118.                 string IEVersion = regKey.GetValue("Version").ToString();  
  119.   
  120.                 string strVersion = IEVersion.Substring(0, 1);  
  121.                 return int.Parse(strVersion);  
  122.             }  
  123.             catch (Exception)  
  124.             {  
  125.                 return 6;  
  126.             }  
  127.         }  
  128.         #endregion  
  129.     }  
  130.   
  131.     public class OperationOnIE6  
  132.     {  
  133.         #region new a window with url  
  134.         public static Process NewUrl(string defaultIE,string url)  
  135.         {  
  136.             Process p = new Process();  
  137.             p.StartInfo.FileName = defaultIE;  
  138.             p.StartInfo.Arguments = url;  
  139.             p.Start();  
  140.             return p;  
  141.         }  
  142.         #endregion  
  143.  
  144.         #region get url  
  145.         public static string GetUrl(int hIEWnd)  
  146.         {  
  147.             //using spy++ to find the type of window  
  148.             int hCtrlWnd = Win32API.FindWindowEx(hIEWnd, 0, "WorkerW"null);  
  149.             hCtrlWnd = Win32API.FindWindowEx(hCtrlWnd, 0, "ReBarWindow32"null);  
  150.             hCtrlWnd = Win32API.FindWindowEx(hCtrlWnd, 0, "ComboBoxEx32"null);  
  151.             hCtrlWnd = Win32API.FindWindowEx(hCtrlWnd, 0, "ComboBox"null);  
  152.             hCtrlWnd = Win32API.FindWindowEx(hCtrlWnd, 0, "Edit"null);  
  153.   
  154.             StringBuilder buffer = new StringBuilder(1024);  
  155.             //send message to get url  
  156.             int num = Win32API.SendMessage(hCtrlWnd, ConstData.WM_GETTEXT, 1024, buffer);  
  157.             return buffer.ToString();  
  158.         }  
  159.         #endregion          
  160.  
  161.         #region set url  
  162.         public static void SetUrl(int hIEWnd, StringBuilder strUrl)  
  163.         {  
  164.             //using spy++ to find the type of window  
  165.             int hCtrlWnd = Win32API.FindWindowEx(hIEWnd, 0, "WorkerW"null);  
  166.             hCtrlWnd = Win32API.FindWindowEx(hCtrlWnd, 0, "ReBarWindow32"null);  
  167.             hCtrlWnd = Win32API.FindWindowEx(hCtrlWnd, 0, "ComboBoxEx32"null);  
  168.             hCtrlWnd = Win32API.FindWindowEx(hCtrlWnd, 0, "ComboBox"null);  
  169.             int hUrlWnd = Win32API.FindWindowEx(hCtrlWnd, 0, "Edit"null);  
  170.   
  171.             //set IE url  
  172.             Win32API.SendMessage(hUrlWnd, ConstData.WM_SETTEXT, 0, strUrl);  
  173.             //refresh IE  
  174.             Win32API.SendMessage(hUrlWnd, ConstData.WM_KEYDOWN, ConstData.VK_RETURN, null);  
  175.             //activate the window  
  176.             Win32API.SendMessage(hIEWnd, ConstData.WM_ACTIVATE, 0, null);  
  177.         }  
  178.         #endregion  
  179.     }  
  180. }  


编写应用程序,调用命名空间AutoOperationOnIE6的类。

 

[c-sharp] view plain copy print ?
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8.   
  9. using System.Collections;  
  10. using System.Diagnostics;  
  11. using System.Runtime.InteropServices;  
  12.   
  13. using AutoOperationOnIE6;  
  14.   
  15. namespace TestIE6Operation  
  16. {  
  17.     public partial class FrmMain : Form  
  18.     {  
  19.         private ArrayList ie6Process = new ArrayList();  
  20.   
  21.         public FrmMain()  
  22.         {  
  23.             InitializeComponent();  
  24.         }  
  25.   
  26.         private void btnClose_Click(object sender, EventArgs e)  
  27.         {  
  28.             this.Close();  
  29.         }  
  30.   
  31.         private void btnClear_Click(object sender, EventArgs e)  
  32.         {  
  33.             urlList.Items.Clear();  
  34.             tbInfo.Clear();  
  35.             tbModules.Clear();  
  36.             tbThreads.Clear();  
  37.             ie6Process.Clear();  
  38.             tbUrl.Text = "about:blank";              
  39.         }  
  40.   
  41.         private void btnGetUrl_Click(object sender, EventArgs e)  
  42.         {  
  43.             ie6Process.Clear();  
  44.             urlList.Items.Clear();  
  45.               
  46.             Process[] process = Process.GetProcessesByName("IEXPLORE");  
  47.             foreach (Process curie in process)  
  48.             {  
  49.                 IntPtr ieHandle = curie.MainWindowHandle;  
  50.                 string strurl = OperationOnIE6.GetUrl(ieHandle.ToInt32());  
  51.                 ie6Process.Add(curie);  
  52.                 urlList.Items.Add(strurl);  
  53.             }  
  54.         }  
  55.   
  56.         private void urlList_MouseDoubleClick(object sender, MouseEventArgs e)  
  57.         {  
  58.             if (urlList.Items.Count==0)  
  59.                 return;  
  60.   
  61.             int index = urlList.SelectedIndex;  
  62.             Process curprocess = (Process)ie6Process[index];  
  63.   
  64.             string strinfo = string.Empty;  
  65.             strinfo += "machine name : " + curprocess.MachineName + "/r/n";  
  66.             strinfo += "main module  : " + curprocess.MainModule.ToString() + "/r/n";  
  67.             strinfo += "process id   : " + curprocess.Id.ToString() + "/r/n";  
  68.             strinfo += "window handle: " + curprocess.MainWindowHandle.ToString() + "/r/n";  
  69.             strinfo += "window title : " + curprocess.MainWindowTitle;  
  70.             tbInfo.Text = strinfo;  
  71.   
  72.             strinfo = string.Empty;  
  73.             ProcessModuleCollection modules = curprocess.Modules;  
  74.             for (int i = 0; i < modules.Count;i++ )  
  75.             {  
  76.                 strinfo += "module Name : " + modules[i].ModuleName + "/r/n";  
  77.                 strinfo += "file Name   : " + modules[i].FileName + "/r/n";  
  78.                 strinfo += "file Version: " + modules[i].FileVersionInfo.FileVersion + "/r/n";  
  79.                 strinfo += "company name: " + modules[i].FileVersionInfo.CompanyName + "/r/n";  
  80.                 strinfo += "comments    : " + modules[i].FileVersionInfo.Comments + "/r/n/r/n";  
  81.             }  
  82.             tbModules.Text = strinfo;  
  83.   
  84.             strinfo = string.Empty;  
  85.             ProcessThreadCollection threads = curprocess.Threads;  
  86.             for (int i = 0; i < threads.Count; i++)  
  87.             {  
  88.                 strinfo += "thread id : " + threads[i].Id + "/r/n";  
  89.                 strinfo += "os kernel : " + threads[i].PrivilegedProcessorTime.ToString() + "/r/n";  
  90.                 strinfo += "start time: " + threads[i].StartTime+ "/r/n";  
  91.                 strinfo += "total time: " + threads[i].TotalProcessorTime.ToString() + "/r/n";  
  92.                 strinfo += "user time : " + threads[i].UserProcessorTime+ "/r/n/r/n";  
  93.             }  
  94.             tbThreads.Text = strinfo;  
  95.         }  
  96.   
  97.         private void btnNewUrl_Click(object sender, EventArgs e)  
  98.         {  
  99.             if(tbUrl.Text==string.Empty)  
  100.             {  
  101.                 MessageBox.Show("please input a url""prompt information", MessageBoxButtons.OK, MessageBoxIcon.Information);  
  102.                 tbUrl.Focus();  
  103.                 return;  
  104.             }  
  105.   
  106.             CommonIEOperation.GetDefaultBrowser();  
  107.             Process p = OperationOnIE6.NewUrl(CommonIEOperation.DefaultBrowserPath, tbUrl.Text);  
  108.   
  109.             urlList.Items.Add(tbUrl.Text);  
  110.             ie6Process.Add(p);  
  111.         }  
  112.   
  113.         private void btnSetUrl_Click(object sender, EventArgs e)  
  114.         {  
  115.             if (urlList.Items.Count == 0)  
  116.                 return;  
  117.   
  118.             if(urlList.SelectedIndex<0)  
  119.             {  
  120.                 MessageBox.Show("please select a url""prompt information", MessageBoxButtons.OK, MessageBoxIcon.Information);  
  121.                 urlList.Focus();  
  122.                 return;  
  123.             }  
  124.             if (tbUrl.Text == string.Empty)  
  125.             {  
  126.                 MessageBox.Show("please input a url""prompt information", MessageBoxButtons.OK, MessageBoxIcon.Information);  
  127.                 tbUrl.Focus();  
  128.                 return;  
  129.             }  
  130.   
  131.             int index = urlList.SelectedIndex;  
  132.             int hIEWnd=((Process)ie6Process[index]).MainWindowHandle.ToInt32();  
  133.   
  134.             StringBuilder strUrl = new StringBuilder();  
  135.             strUrl.Append(tbUrl.Text);  
  136.             OperationOnIE6.SetUrl(hIEWnd, strUrl);  
  137.   
  138.             urlList.Items[index] = strUrl;  
  139.         }  
  140.   
  141.         private void btnDelete_Click(object sender, EventArgs e)  
  142.         {  
  143.             if (urlList.Items.Count > 0)  
  144.             {  
  145.                 if (urlList.SelectedIndex < 0)  
  146.                 {  
  147.                     MessageBox.Show("please select a url""prompt information", MessageBoxButtons.OK, MessageBoxIcon.Information);  
  148.                     urlList.Focus();  
  149.                     return;  
  150.                 }  
  151.   
  152.                 int index = urlList.SelectedIndex;  
  153.                 ((Process)ie6Process[index]).Kill();  
  154.                 ie6Process.RemoveAt(index);  
  155.                 urlList.Items.RemoveAt(index);  
  156.                 if (index > 0)  
  157.                     urlList.SelectedIndex = index - 1;  
  158.                 else  
  159.                 {  
  160.                     if (urlList.Items.Count > 0)  
  161.                         urlList.SelectedIndex = 0;  
  162.                     else  
  163.                         urlList.SelectedIndex = -1;  
  164.                 }  
  165.             }  
  166.         }  
  167.     }  
  168. }  
 

 

运行结果如下:

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值