为了让大家都能够使用demo,我以IE为测试对象,另外为了突出重点,所以如何获取窗口句柄我就不做演示了(不清楚的童鞋,可以去Google下哈),句柄值我使用spy++获得

大家可以下载demo(附:spy++)到本地进行调试学习,希望这篇文章对大家有所帮助

知识点:

1.Internet_Explorer_Server

2.msthml

3.API:RegisterWindowMessage

4.API:ObjectFromLresult

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
using mshtml;namespace 获取类名Internet_Explorer_Server控件的内容
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){if(String.IsNullOrEmpty(tbHandle.Text)){MessageBox.Show("请写好窗口类名为:Internet Explorer_Server的窗口句柄");return;}mshtml.IHTMLDocument2 id = GetHtmlDocument(int.Parse(tbHandle.Text));textBox1.Text = id.body.innerHTML;}      class Win32API{[DllImport("user32", EntryPoint = "SendMessage")]public static extern int SendMessage(int hwnd, int wMsg, int wParam, ref int lParam);[DllImport("user32", EntryPoint = "RegisterWindowMessage")]public static extern int RegisterWindowMessage(string lpString);[DllImport("OLEACC.DLL", EntryPoint = "ObjectFromLresult")]public static extern int ObjectFromLresult(int lResult,ref System.Guid riid,int wParam,[MarshalAs(UnmanagedType.Interface), System.Runtime.InteropServices.In, System.Runtime.InteropServices.Out]ref System.Object ppvObject//注意这个函数ObjectFromLresult的声明);}public mshtml.IHTMLDocument2 GetHtmlDocument(int hwnd){System.Object domObject = new System.Object();int tempInt = 0;System.Guid guidIEDocument2 = new Guid();int WM_Html_GETOBJECT =Win32API.RegisterWindowMessage("WM_Html_GETOBJECT");//定义一个新的窗口消息int W = Win32API.SendMessage(hwnd, WM_Html_GETOBJECT, 0, ref tempInt);//注:第二个参数是RegisterWindowMessage函数的返回值int lreturn = Win32API.ObjectFromLresult(W, ref guidIEDocument2, 0, ref domObject);mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)domObject;return doc;}}
}

这里,我以IE打开的百度首页为测试对象,效果如下:


C#获取类名为Internet_Explorer_Server控件的内容相关推荐

  1. vb实现webbrowser显示html,VB.NET 通过窗口句柄,获取webbrowser控件HTML内容

    VB.NET通过窗口句柄,获取webbrowser控件HTML内容 通过Sendmessage获取IE浏览器内容 webbrowser控件内容获取 Class Win32API     _ Publi ...

  2. javascript获取asp.net服务器端控件的值(2009-10-31 15:24:26)转载标签:杂谈 分类:技术分类

    javascript获取asp.net服务器端控件的值 (2009-10-31 15:24:26) 转载 标签: 杂谈 分类:技术分类 代码如下: <%@ Page Language=" ...

  3. C++ 一个程序获取另一个程序Edit控件的内容

    转载地址:https://www.cnblogs.com/lujin49/p/4796502.html //一个程序获取另一个程序Edit控件的内容 //根据指定程序的标题名获取改程序窗口的句柄 HW ...

  4. javascript获取asp.net服务器端控件的值

    代码如下: <%@ Page Language="C#" CodeFile="A.aspx.cs" Inherits="OrderManage_ ...

  5. Js获取file上传控件的文件路径总结

    总结一个获取file上传控件文件路径的方法 firefox由于保护机制只有文件名,不能获取完整路径. document.getElementById('file').onchange = functi ...

  6. [代码]获取源页的控件值

    重点总结 在ASP.NET中,要想从目标页获取源页的数据信息,可以使用两种方法: 一是通过获取源页的控件进而获取控件的属性值. 二是直接通过获取源页公开的公共属性来获取源页数据. 本示例代码则演示如何 ...

  7. C#获取指定controlName的控件;遍历控件,反射控件类型等

    一般情况下或许用不到,但是也有特殊情况下会需要使用类似的功能. 1.比如你的软件做了多个界面版本,有中文版,英文版等等,就需要控制界面显示.通常会把控件名称与显示文字以键值对的形式存储到外部数据库或者 ...

  8. Android Include的使用,获取include 里面的控件

    include 就是在一个布局中引入另一个布局,include 可以使相同的页面就写一次,提高了共同布局的复用性. 1.先定义一个共用的布局 <?xml version="1.0&qu ...

  9. C#在WinForm中实现清空指定类型控件的内容

    实现在Winform中递归控件来清空指定类型控件的内容(因为在Winform中,各个控件是有层次关系的,不能简单地依靠遍历this.controls) private void ClearConten ...

最新文章

  1. execute、executeQuery和executeUpdate之间的区别
  2. 拿到饿了么 P7 Offer,却一轮游途虎……
  3. @MyBatis主键返回
  4. 文档容器iOS网络编程-iCloud文档存储编程实例
  5. Matlab与simulink中的数据类型
  6. 父亲节,程序员几条代码硬核示爱
  7. Java Servlet 使用slf4j配置log4j
  8. yolov3为什么对大目标检测不好_【目标检测简史】进击的YOLOv3,目标检测网络的巅峰之作...
  9. 如何进行Java EE性能测试与调优
  10. atitit 常见个人与企业与组织机构的信息化.docx
  11. 填坑---override、overload、overwrite
  12. Linux远程服务器环境搭建
  13. python 分类变量回归_虚拟/分类变量线性回归
  14. EXE捆绑机制作原理
  15. 0字节文件无法删除怎么办
  16. Android清理缓存工具类
  17. 【A Unified Model for Multi-class Anomaly Detection, NeurIPS 2022】
  18. 坐标旋转公式-- 角度和弧度
  19. 分析三大移动应用的发展趋势
  20. unity Assetstore 和unityhub下载的东西在哪里

热门文章

  1. 具有OpenCV和相似度测量的视频输入
  2. 从C ++定义QML类型
  3. 将C ++类型的属性公开给QML
  4. OpenGL绘制Triangle三角形
  5. QT的QShortcut类的使用
  6. QT的QDataStream类的使用
  7. cocos2dx中关于Action动作的相关API的详细介绍
  8. 网站用户访问速度监测分析项目
  9. 【tensorflow】Sequential 模型方法 compile, model.compile
  10. python魅力_魅力python------if - else 语句