vb.net 教程 20-3 控制Ie浏览器 6 获得Ie窗口 mshtml.IHTMLDocument2

版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。

五、获得Ie窗口 mshtml.IHTMLDocument2

本小节是比较关键的一步,从Internet Explorer_Server获得IHTMLDocument2对象

使用到的api函数:

1、RegisterWindowMessage()函数定义一个新的窗口消息

    Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (
        ByVal lpString As String) As Integer

2、SendMessageTimeout()函数将指定的消息发送到一个或多个窗口

    Private Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" (
        ByVal hWND As Integer,
        ByVal msg As Integer,
        ByVal wParam As Integer,
        ByRef lParam As Integer,
        ByVal fuFlags As Integer,
        ByVal uTimeout As Integer,
        ByRef lpdwResult As Integer) As Integer

3、ObjectFromLresult()函数检索是一个基于先前生成的对象的引用访问的对象请求的接口指针

    Private Declare Function ObjectFromLresult Lib "oleacc" (
        ByVal lResult As Integer,
        ByRef riid As Guid,
        ByVal wParam As Integer,
        ByRef ppvObject As mshtml.IHTMLDocument2) As Integer

 

4、用到的常量:

    Private Const SMTO_ABORTIFHUNG = &H2
    Private Const SMTO_NOTIMEOUTIFNOTHUNG = &H8


具体代码:

 

    ''' <summary>
    ''' 从Internet Explorer_Server获得IHTMLDocument2对象
    ''' </summary>
    ''' <param name="IEShwnd">Internet Explorer_Server 句柄</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ''' 
    Public Function getDocumentfromIES(ByVal IEShwnd As Integer) As mshtml.IHTMLDocument2
        Dim WM_Html_GETOBJECT As Integer
        WM_Html_GETOBJECT = RegisterWindowMessage("WM_HTML_GETOBJECT")
        Dim tempInt As Integer = 0
        SendMessageTimeout(IEShwnd, WM_Html_GETOBJECT, 0, 0, SMTO_ABORTIFHUNG, 1000, tempInt)

        Dim GUID_IHTMLDocument As New Guid("{626FC520-A41E-11CF-A731-00A0C9082637}")

        Dim I_IEdocument As mshtml.IHTMLDocument2
        If ObjectFromLresult(tempInt, GUID_IHTMLDocument, 0, I_IEdocument) = 0 Then
            Return I_IEdocument
        End If
        Return Nothing
    End Function


通过getDocumentfromIES()就可以获得某个Internet Explorer_Server关联的IHTMLDocument2

 

 

由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。

学习更多vb.net知识,请参看vb.net 教程 目录

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值