VB 获取 Internet Explorer_Server 里面的内容

VB 获取 Internet Explorer_Server 里面的内容,第1张

概述模块中的代码: Option Explicit'' 要求:使用本模块时需要在工程中引用 Microsoft HTML Object Library。'Private Type GUID Data1 As Long Data2 As Integer Data3 As Integer Data4(0 To 7) As ByteEnd TypePrivate

模块中的代码:

Option Explicit'' 要求:使用本模块时需要在工程中引用 Microsoft HTML Object library。'Private Type GUID    Data1 As Long    Data2 As Integer    Data3 As Integer    Data4(0 To 7) As ByteEnd TypePrivate Declare Function GetClassname lib "user32" _    Alias "GetClassnameA" ( _    ByVal hWND As Long,_    ByVal lpClassname As String,_    ByVal nMaxCount As Long) As LongPrivate Declare Function EnumChildwindows lib "user32" ( _    ByVal hWndParent As Long,_    ByVal lpEnumFunc As Long,_    lParam As Long) As LongPrivate Declare Function RegisterWindowMessage lib "user32" _    Alias "RegisterWindowMessageA" ( _    ByVal lpString As String) As LongPrivate Declare Function SendMessageTimeout lib "user32" _    Alias "SendMessageTimeoutA" ( _    ByVal hWND As Long,_    ByVal msg As Long,_    ByVal wParam As Long,_    lParam As Any,_    ByVal fuFlags As Long,_    ByVal uTimeout As Long,_    lpDWResult As Long) As LongPrivate Const SMTO_ABORTIFHUNG = &H2Private Declare Function ObjectFromLresult lib "oleacc" ( _    ByVal lResult As Long,_    riID As GUID,_    ppvObject As Any) As LongPublic Declare Function FinDWindow lib "user32" _    Alias "FinDWindowA" ( _    ByVal lpClassname As String,_    ByVal lpWindowname As String) As Long'' 函数:IEDOMFromhWnd。'' 返回:一个 Webbrowser 窗口的 IHTMLdocument 对象接口。'' hWnd 参数:Webbrowser 控件的句柄或 Webbrowser 控件所在窗口的句柄。'Public Function IEDOMFromhWnd(ByVal hWND As Long) As IHTMLdocument    Dim IID_IHTMLdocument As GUID    Dim hWndChild As Long    Dim lRes As Long    Dim lMsg As Long    Dim hr As Long    If hWND <> 0 Then        If Not IsIEServerWindow(hWND) Then            ' 查找一个 Webbrowser 控件。            EnumChildwindows hWND,AddressOf EnumChildProc,hWND        End If        If hWND <> 0 Then            ' 注册消息。            lMsg = RegisterWindowMessage("WM_HTML_GetoBJECT")            ' 获取对象的指针。            Call SendMessageTimeout(hWND,lMsg,_            SMTO_ABORTIFHUNG,1000,lRes)            If lRes Then                ' 初始化接口 ID。                With IID_IHTMLdocument                    .Data1 = &H626FC520                    .Data2 = &HA41E                    .Data3 = &H11CF                    .Data4(0) = &HA7                    .Data4(1) = &H31                    .Data4(2) = &H0                    .Data4(3) = &HA0                    .Data4(4) = &HC9                    .Data4(5) = &H8                    .Data4(6) = &H26                    .Data4(7) = &H37                End With                ' 利用指针 lRes 获取 IHTMLdocument 对象。                hr = ObjectFromLresult(lRes,IID_IHTMLdocument,_0,IEDOMFromhWnd)            End If        End If    End IfEnd FunctionPrivate Function IsIEServerWindow(ByVal hWND As Long) As Boolean    Dim lRes As Long    Dim sClassname As String    ' 初始化缓冲区大小。    sClassname = String$(255,0)    ' 获取 hWnd 句柄拥有者的类名称。    lRes = GetClassname(hWND,sClassname,Len(sClassname))    sClassname = left$(sClassname,lRes)    IsIEServerWindow = StrComp(sClassname,_            "Internet Explorer_Server",_            vbTextCompare) = 0End FunctionFunction EnumChildProc(ByVal hWND As Long,lParam As Long) As Long    If IsIEServerWindow(hWND) Then        lParam = hWND    Else        EnumChildProc = 1    End IfEnd Function

窗体中的代码:
Option ExplicitPrivate Sub Command1_Click()    Dim hWND As Long    Dim s As String * 255    Dim l As Long    hWND = FinDWindow("IMWindowClass",vbNullString)    GETTEXT hWNDEnd SubPrivate Sub GETTEXT(hWND As Long)    '创建一个 IHTMLdocument 对象。    Dim objIES As New HTMLdocument    Set objIES = IEDOMFromhWnd(hWND)                                            'hWnd 这个东西你肯定有 N 种办法得到。    '应用。    '例如下面是获得一个 Webbrowser 控件当前浏览网页的地址和该网页的 HTML 源码。    Text1.Text = objIES.url & vbCrLf & vbCrLf & objIES.documentElement.INNERHTMLEnd Sub
总结

以上是内存溢出为你收集整理的VB 获取 Internet Explorer_Server 里面的内容全部内容,希望文章能够帮你解决VB 获取 Internet Explorer_Server 里面的内容所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1278159.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存