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浏览器操作类的更多相关文章

  1. [转]html5 js 访问 sqlite 数据库的操作类

    本文转自:http://blog.csdn.net/tsxw24/article/details/7613815 webkit 核心的浏览器提供了 3个 api接口,用于访问本地sqlite数据,但使 ...

  2. [C#] 常用工具类——文件操作类

    /// <para> FilesUpload:工具方法:ASP.NET上传文件的方法</para> /// <para> FileExists:返回文件是否存在&l ...

  3. Java文件操作类效率对比

    前言 众所周知,Java中有多种针对文件的操作类,以面向字节流和字符流可分为两大类,这里以写入为例: 面向字节流的:FileOutputStream 和 BufferedOutputStream 面向 ...

  4. python3+selenium框架设计05-配置文件和浏览器引擎类

    python3配置文件的增删改查等操作可以使用内置的ConfigParser模块,可以自行百度学习,也可以看Python3学习笔记27-ConfigParser模块 配置文件一般存放着环境信息,比如u ...

  5. Cookie操作类、 包括创建、读取、修改、获取、销毁cookie

    Cookie操作类. 包括创建.读取.修改.获取.销毁cookie import java.util.Hashtable; import java.util.Iterator; import java ...

  6. File 文件操作类 大全

    File  文件操作类  大全 许多人都会对文件操作感到很难  我也是  但是一个好的项目中必定会涉及到文件操作的 文件的复制 粘贴  等等等 公司大佬写了 一个文件操作的工具类 感觉还是棒棒的啦   ...

  7. php socket通信演示以及socket操作类

    准备做Java的课程设计,一个通讯录.采用C/S架构.客户端用java FX和Java,服务器端用php,采用socket通信. 下面来讲一讲php的socket通信: 讲之前,得先讲一下TCP/IP ...

  8. 【知识必备】ezSQL,最好用的数据库操作类,让php操作sql更简单~

    最近用php做了点小东东,用上了ezSQL,感觉真的很ez,所以拿来跟大家分享一下~ ezSQL是一个非常好用的PHP数据库操作类.著名的开源博客WordPress的数据库操作就使用了ezSQL的My ...

  9. JQuery操作类数组的工具方法

    JQuery学习之操作类数组的工具方法 在很多时候,JQuery的$()函数都返回一个类似数据的JQuery对象,例如$('div')将返回div里面的所有div元素包装的JQuery对象.在这中情况 ...

随机推荐

  1. WPF 精修篇 长时间线程加取消功能

    原文:WPF 精修篇 长时间线程加取消功能 <Grid> <Grid.RowDefinitions> <RowDefinition Height="11*&qu ...

  2. ASP.NET MVC EF 连接数据库(二)-----Model First

    Model first (VS2015 ,Sql Server2014) 新建MVC项目     右键product ,新增标量属性(数据库表中的字段)   Ctrl + S 保存页面,右键“根据模型 ...

  3. Math基础使用

    /* java.lang.Math类是数学相关的工具类,里面提供的大量静态方法,完成与数学运算的操作 public static double abs(double num):获取绝对值. publi ...

  4. oracle高级部分

    回顾 多表关联查询的方式 内连接 根据AB表关联的条件进行过滤查询,只保留满足条件数据 Select * from a,b where a.xxx=b.xxx; Select * from a inn ...

  5. 高性能的编程IO与NIO阻塞分析

    1.什么是阻塞,什么是非阻塞? 阻塞:结果返回之前,线程一直被挂起. 非阻塞:做一件事,尝试去做 2.传统IO模型 socket编程:

  6. 转:Oracle中SQL语句执行过程中

    Oracle中SQL语句执行过程中,Oracle内部解析原理如下: 1.当一用户第一次提交一个SQL表达式时,Oracle会将这SQL进行Hard parse,这过程有点像程序编译,检查语法.表名.字 ...

  7. 苹果电脑Mac系统如何安装Adobe Flash Player

    一)安装/更新Adobe Flash Player 开系统偏好设置 , Flash player  更新,立即检查/立刻安装: Flash插件官方每月常规更新1~2次,为避免频繁过期,建议设置为允许A ...

  8. 在ARM64位开发板上兼容ARM32位的可执行程序

    邮箱:pengdonglin137@163.com 参考:https://stackoverflow.com/questions/1706328/how-do-shared-libraries-wor ...

  9. OpenLDAP 常用命令

    OpenLDAP 常用命令 本文原始地址:https://sitoi.cn/posts/5308.html ldapsearch ldapsearch - ldap 搜索工具 ldapsearch 实 ...

  10. ubuntu安装vbox虚拟机

    ubuntu安装vbox虚拟机 一.安装准备 1.查看主机配置 二.下载安装包    (建议将安装包下载并保存) a.下载virtualbox安装包 下载链接https://www.virtualbo ...