VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > vb >
  • vb.net 教程 20-3 控制Ie浏览器 6

版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
 
五、获得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 教程 目录
 
 
————————————————
版权声明:本文为CSDN博主「VB.Net」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/uruseibest/article/details/77924452

相关教程