加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

vb.net 教程 20-3 控制Ie浏览器 6

发布时间:2020-12-16 22:19:00 所属栏目:大数据 来源:网络整理
导读:五、获得Ie窗口 mshtml.IHTMLDocument2 本小节是比较关键的一步,从Internet Explorer_Server获得IHTMLDocument2对象 使用到的api函数: 1、RegisterWindowMessage()函数定义一个新的窗口消息 Private Declare Function RegisterWindowMessage Lib "user32"
五、获得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,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,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,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 教程 目录

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读