Public Class IEDom
Declare Function ObjectFromLresult Lib "oleacc" (ByVal lResult As Int32, ByRef riid As System.Guid, ByVal wParam As Int32, ByRef ppvObject As IHTMLDocument) As Int32
Dim win32 As New Win32Functions
Public Function IEDOMFromhWnd(ByVal hWnd As IntPtr) As IHTMLDocument
Dim IID_IHTMLDocument As System.Guid = New System.Guid("626FC520-A41E-11CF-A731-00A0C9082637")
Dim hWndChild As Int32
Dim lRes As Int32
Dim lMsg As Int32
Dim hr As Int32
If Not hWnd.Equals(0) Then
If Not IsIEServerWindow(hWnd) Then
' Get 1st child IE server window
win32.EnumChildWindows(hWnd, AddressOf EnumChild, hWnd)
End If
If Not hWnd.Equals(0) Then
' Register the message
lMsg = win32.RegisterWindowMessage("WM_HTML_GETOBJECT")
' Get the object
Call win32.SendMessageTimeout(hWnd, lMsg, 0, 0, win32.SMTO_ABORTIFHUNG, 1000, lRes)
If lRes Then
' Get the object from lRes
hr = ObjectFromLresult(lRes, IID_IHTMLDocument, 0, IEDOMFromhWnd)
If hr Then Throw New COMException(hr)
End If
End If
End If
End Function
Private Function EnumChild(ByVal hWnd As IntPtr, ByRef lParam As IntPtr) As Int32
If IsIEServerWindow(hWnd) Then
lParam = hWnd
Else
EnumChild = 1
End If
End Function
Private Function IsIEServerWindow(ByVal hWnd As IntPtr) As Boolean
Dim Res As Int32
Dim ClassName As StringBuilder = New StringBuilder(100)
' Get the window class name
Res = win32.GetClassName(hWnd, ClassName, ClassName.MaxCapacity)
IsIEServerWindow = StrComp(ClassName.ToString(), "Internet Explorer_Server", CompareMethod.Text) = 0
End Function
End Class
错误提示:错误 1 未定义类型“Win32Functions”。
代码来源:
http://www.vbforums.com/showthread.php?t=357949