日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C# IE浏览器操作类

發布時間:2024/9/20 C# 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C# IE浏览器操作类 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
using System; using System.Collections.Generic; using System.Drawing; using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; using mshtml; using SHDocVw;namespace WebClick_Tool { /// <summary> /// IE瀏覽器操作 /// </summary> public class IETool { /// <summary> /// IE句柄 /// </summary> public int IEHandle { get; set; } /// <summary> /// 瀏覽器 /// </summary> public IWebBrowser2 IEBrowser { get; set; } /// <summary> /// 當前頁面Document /// </summary> public HTMLDocumentClass Document { get; set; } /// <summary> /// 瀏覽器標頭高度 /// </summary> public int BrowserH { get; set; } /// <summary> /// 初始化是否成功 /// </summary> public bool Suc { get; set; } /// <summary> /// 頭部標題 /// </summary> public string HeadTitle { get; set; } /// <summary> /// 失敗頭部標題 /// </summary> public string BadHeadTitle { get; set; } /// <summary> /// 瀏覽器高度 /// </summary> public int HeighBro { get; set; }public IETool(string HeadTitleO,string BadTitle) { HeadTitle = HeadTitleO; BadHeadTitle = BadTitle; HeighBro = -1; if (GetHandleOfBrowser()) Suc = true; else Suc = false; try { GetHtml(false); } catch { } } #region 系統API /// <summary> /// 找窗口句柄 /// </summary> /// <param name="lpClassName"></param> /// <param name="lpWindowName"></param> /// <returns></returns> [DllImport("user32", EntryPoint = "FindWindow")] public static extern int FindWindowA(string lpClassName, string lpWindowName); /// <summary> /// 窗體發送消息 /// </summary> /// <param name="hWnd"></param> /// <param name="Msg"></param> /// <param name="wParam"></param> /// <param name="lParam"></param> /// <returns></returns> [DllImport("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); #endregion /// <summary> /// 獲取IE句柄 /// </summary> /// <returns></returns> private bool GetHandleOfBrowser() { IEHandle = FindWindowA("IEFrame", null); if (IEHandle == 0) return false; else return true; } /// <summary> /// IE窗體最大化 /// </summary> public void SetMaxStyle(int Handle) { SendMessage(new IntPtr((Handle != 0 ? Handle : IEHandle)), 274, 61488, 0); } /// <summary> /// 獲取源代碼 /// </summary> /// <returns></returns> public string GetHtml(bool Sacn) { string TempStr = ""; //初始化所有IE窗口 IShellWindows sw = new ShellWindowsClass(); for (int i = sw.Count - 1; i >= 0; i--) { //得到每一個IE的 IWebBrowser2 對象 IWebBrowser2 iwb2 = sw.Item(i) as IWebBrowser2; //比對 得到的 句柄是否符合查找的窗口句柄 if (iwb2!=null&&iwb2.HWND == IEHandle) { Document = (HTMLDocumentClass)iwb2.Document; if(Sacn) if ((Document == null || Document.title == null || Document.title != HeadTitle) && !Document.title.Contains(BadHeadTitle)) { continue; }iwb2.StatusBar = false;//狀態欄 SendMessage(new IntPtr(iwb2.HWND), 274, 61488, 0); if (Document == null) return ""; if (Document.title == "百度一下,你就知道" || Document.title == "360搜索 - 干凈、安全、可信任的搜索引擎") TempStr = "<!doctype html>" + ((HTMLDocumentClass)iwb2.Document).documentElement.outerHTML; else TempStr = ((HTMLDocumentClass)iwb2.Document).documentElement.outerHTML; try { HeighBro = ((IHTMLElement2)Document.body).scrollHeight; } catch { } break; } } return TempStr; }} }

總結

以上是生活随笔為你收集整理的C# IE浏览器操作类的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。