博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#获取类名为Internet_Explorer_Server控件的内容
阅读量:6976 次
发布时间:2019-06-27

本文共 2415 字,大约阅读时间需要 8 分钟。

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

      大家可以到本地进行调试学习,希望这篇文章对大家有所帮助

知识点:

1.Internet_Explorer_Server

2.

3.API:

4.API:

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打开的百度首页为测试对象,效果如下:


 

转载地址:http://loesl.baihongyu.com/

你可能感兴趣的文章
javascript测试
查看>>
Java线程池
查看>>
解决方案:如何让ADC产品将HTTP请求负载的更加均衡
查看>>
开始运行你的第一个Java Web 项目
查看>>
PHP学习:$_GET,$_POST,$_REQUEST和$_SERVER的一些用法,以及parse_str方法
查看>>
java下DES加密与解密
查看>>
Nagios使用SendEmail发送邮件
查看>>
Domino8.5.1和Exchange2010共用一个邮件域实现邮件收发
查看>>
截图留存
查看>>
linux PDF转换为SWF
查看>>
ASP.net 中的AJAX学习记录之四 updateProgress控件的简单用法
查看>>
怎样自动生成makefile
查看>>
Windows2008R2 AD降级错误解决方案
查看>>
datagridview的数据库设计与使用
查看>>
资源管理器的学习笔记一
查看>>
JAVA中写时复制(Copy-On-Write)Map实现
查看>>
推荐12个漂亮的 CSS3 按钮实现方案
查看>>
顺序栈
查看>>
[译] OpenStack Kilo 版本中 Neutron 的新变化
查看>>
Lintcode: Sqrt(X)
查看>>