-
VB.NET 通过窗口句柄,获取webbrowser控件HTML内容
<DllImport("user32.dll", EntryPoint:="FindWindow")> _
Public Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint:="FindWindowEx")> _
Public Shared Function FindWindowEx(ByVal hwndParent As IntPtr, ByVal hwndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Shared Function RegisterWindowMessage(ByVal lpString As String) As UInteger
End Function
<DllImport("oleacc.dll", PreserveSig:=False)> _
Public Shared Function ObjectFromLresult(ByVal lResult As UIntPtr, <MarshalAs(UnmanagedType.LPStruct)> ByVal refiid As Guid, ByVal wParam As IntPtr) As <MarshalAs(UnmanagedType.[Interface])> Object
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Shared Function SendMessageTimeout(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As UIntPtr, ByVal lParam As IntPtr, ByVal fuFlags As SendMessageTimeoutFlags, ByVal uTimeout As UInteger, _
ByRef lpdwResult As UIntPtr) As IntPtr
End Function
Public Enum SendMessageTimeoutFlags As UInteger
SMTO_NORMAL = &H0
SMTO_BLOCK = &H1
SMTO_ABORTIFHUNG = &H2
SMTO_NOTIMEOUTIFNOTHUNG = &H8
End Enum
End Class
Public Class IEWindow
Public Shared Function GetIEWindowDocument2(ByVal editHWnd5 As IntPtr) As HTMLDocumentClass
Dim lRes As New UIntPtr()
Dim app2_GenerateEvent As UInteger = Win32API.RegisterWindowMessage("WM_HTML_GETOBJECT")
Win32API.SendMessageTimeout(editHWnd5, app2_GenerateEvent, UIntPtr.Zero, IntPtr.Zero, Win32API.SendMessageTimeoutFlags.SMTO_NOTIMEOUTIFNOTHUNG, 1000, _
lRes)
Dim obj As HTMLDocumentClass = DirectCast(Win32API.ObjectFromLresult(lRes, GetType(IHTMLDocument).GUID, IntPtr.Zero), HTMLDocumentClass)
Return obj
End Function
Public Shared Function GetIEWindowDocument(ByVal windowName As String) As HTMLDocumentClass
Dim lRes As New UIntPtr()
Dim parentHWnd As IntPtr = Win32API.FindWindow(Nothing, windowName)
MessageBox.Show(parentHWnd.ToString())
Dim editHWnd As IntPtr = Win32API.FindWindowEx(parentHWnd, IntPtr.Zero, "SplitterBar", "")
'需要查找的子窗口的类名,也就是输入框
MessageBox.Show(editHWnd.ToString())
Dim editHWnd1 As IntPtr = Win32API.FindWindowEx(editHWnd, IntPtr.Zero, "StandardWindow", "")
'需要查找的子窗口的类名,也就是输入框
MessageBox.Show(editHWnd1.ToString())
Dim editHWnd2 As IntPtr = Win32API.FindWindowEx(editHWnd1, IntPtr.Zero, "SimpleBrowser", "")
'需要查找的子窗口的类名,也就是输入框
Dim editHWnd3 As IntPtr = Win32API.FindWindowEx(editHWnd2, IntPtr.Zero, "Shell Embedding", "")
'需要查找的子窗口的类名,也就是输入框
Dim editHWnd4 As IntPtr = Win32API.FindWindowEx(editHWnd3, IntPtr.Zero, "Shell DocObject View", "")
'需要查找的子窗口的类名,也就是输入框
MessageBox.Show("Shell DocObject View" & editHWnd2.ToString())
Dim editHWnd5 As IntPtr = Win32API.FindWindowEx(editHWnd4, IntPtr.Zero, "Internet Explorer_Server", "")
'需要查找的子窗口的类名,也就是输入框
MessageBox.Show(editHWnd3.ToString())
Dim app2_GenerateEvent As UInteger = Win32API.RegisterWindowMessage("WM_HTML_GETOBJECT")
Win32API.SendMessageTimeout(editHWnd5, app2_GenerateEvent, UIntPtr.Zero, IntPtr.Zero, Win32API.SendMessageTimeoutFlags.SMTO_NOTIMEOUTIFNOTHUNG, 1000, _
lRes)
Dim obj As HTMLDocumentClass = DirectCast(Win32API.ObjectFromLresult(lRes, GetType(IHTMLDocument).GUID, IntPtr.Zero), HTMLDocumentClass)
Return obj
End Function
End Class
Public Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint:="FindWindowEx")> _
Public Shared Function FindWindowEx(ByVal hwndParent As IntPtr, ByVal hwndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Shared Function RegisterWindowMessage(ByVal lpString As String) As UInteger
End Function
<DllImport("oleacc.dll", PreserveSig:=False)> _
Public Shared Function ObjectFromLresult(ByVal lResult As UIntPtr, <MarshalAs(UnmanagedType.LPStruct)> ByVal refiid As Guid, ByVal wParam As IntPtr) As <MarshalAs(UnmanagedType.[Interface])> Object
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Shared Function SendMessageTimeout(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As UIntPtr, ByVal lParam As IntPtr, ByVal fuFlags As SendMessageTimeoutFlags, ByVal uTimeout As UInteger, _
ByRef lpdwResult As UIntPtr) As IntPtr
End Function
Public Enum SendMessageTimeoutFlags As UInteger
SMTO_NORMAL = &H0
SMTO_BLOCK = &H1
SMTO_ABORTIFHUNG = &H2
SMTO_NOTIMEOUTIFNOTHUNG = &H8
End Enum
End Class
Public Class IEWindow
Public Shared Function GetIEWindowDocument2(ByVal editHWnd5 As IntPtr) As HTMLDocumentClass
Dim lRes As New UIntPtr()
Dim app2_GenerateEvent As UInteger = Win32API.RegisterWindowMessage("WM_HTML_GETOBJECT")
Win32API.SendMessageTimeout(editHWnd5, app2_GenerateEvent, UIntPtr.Zero, IntPtr.Zero, Win32API.SendMessageTimeoutFlags.SMTO_NOTIMEOUTIFNOTHUNG, 1000, _
lRes)
Dim obj As HTMLDocumentClass = DirectCast(Win32API.ObjectFromLresult(lRes, GetType(IHTMLDocument).GUID, IntPtr.Zero), HTMLDocumentClass)
Return obj
End Function
Public Shared Function GetIEWindowDocument(ByVal windowName As String) As HTMLDocumentClass
Dim lRes As New UIntPtr()
Dim parentHWnd As IntPtr = Win32API.FindWindow(Nothing, windowName)
MessageBox.Show(parentHWnd.ToString())
Dim editHWnd As IntPtr = Win32API.FindWindowEx(parentHWnd, IntPtr.Zero, "SplitterBar", "")
'需要查找的子窗口的类名,也就是输入框
MessageBox.Show(editHWnd.ToString())
Dim editHWnd1 As IntPtr = Win32API.FindWindowEx(editHWnd, IntPtr.Zero, "StandardWindow", "")
'需要查找的子窗口的类名,也就是输入框
MessageBox.Show(editHWnd1.ToString())
Dim editHWnd2 As IntPtr = Win32API.FindWindowEx(editHWnd1, IntPtr.Zero, "SimpleBrowser", "")
'需要查找的子窗口的类名,也就是输入框
Dim editHWnd3 As IntPtr = Win32API.FindWindowEx(editHWnd2, IntPtr.Zero, "Shell Embedding", "")
'需要查找的子窗口的类名,也就是输入框
Dim editHWnd4 As IntPtr = Win32API.FindWindowEx(editHWnd3, IntPtr.Zero, "Shell DocObject View", "")
'需要查找的子窗口的类名,也就是输入框
MessageBox.Show("Shell DocObject View" & editHWnd2.ToString())
Dim editHWnd5 As IntPtr = Win32API.FindWindowEx(editHWnd4, IntPtr.Zero, "Internet Explorer_Server", "")
'需要查找的子窗口的类名,也就是输入框
MessageBox.Show(editHWnd3.ToString())
Dim app2_GenerateEvent As UInteger = Win32API.RegisterWindowMessage("WM_HTML_GETOBJECT")
Win32API.SendMessageTimeout(editHWnd5, app2_GenerateEvent, UIntPtr.Zero, IntPtr.Zero, Win32API.SendMessageTimeoutFlags.SMTO_NOTIMEOUTIFNOTHUNG, 1000, _
lRes)
Dim obj As HTMLDocumentClass = DirectCast(Win32API.ObjectFromLresult(lRes, GetType(IHTMLDocument).GUID, IntPtr.Zero), HTMLDocumentClass)
Return obj
End Function
End Class
栏目列表
最新更新
求1000阶乘的结果末尾有多少个0
详解MyBatis延迟加载是如何实现的
IDEA 控制台中文乱码4种解决方案
SpringBoot中版本兼容性处理的实现示例
Spring的IOC解决程序耦合的实现
详解Spring多数据源如何切换
Java报错:UnsupportedOperationException in Col
使用Spring Batch实现批处理任务的详细教程
java中怎么将多个音频文件拼接合成一个
SpringBoot整合ES多个精确值查询 terms功能实
数据库审计与智能监控:从日志分析到异
SQL Server 中的数据类型隐式转换问题
SQL Server中T-SQL 数据类型转换详解
sqlserver 数据类型转换小实验
SQL Server数据类型转换方法
SQL Server 2017无法连接到服务器的问题解决
SQLServer地址搜索性能优化
Sql Server查询性能优化之不可小觑的书签查
SQL Server数据库的高性能优化经验总结
SQL SERVER性能优化综述(很好的总结,不要错
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比