版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
三、获得Ie窗口 Frame Tab 句柄
IEFrame->Frame Tab->TabWindowClass->shell DocObject View->Internet Explorer_Server
上一小节获得了IEFrame句柄,本节继续获得Frame Tab 句柄
先自定义一个结构,用来保存相关句柄信息
Private Structure IEWindowHwnd
Dim IEhwnd As Integer 'IE窗口句柄
Dim FTabhwnd As Integer 'Frame Tab的窗口句柄
Dim Ie_SHwnd As Integer '对应IE_Server的窗口句柄
End Structure
本小节中,Ie_SHwnd暂时用不上。
获得Frame Tab句柄的代码:
''' <summary>
''' 获得指定IE窗口中的"Frame Tab",可能存在多个
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Private Function getIEFrameTab() As ArrayList
Dim IEFrameTabHwndArray As New ArrayList
Dim IEframeTabHwnd As IEWindowHwnd
'获得所有的IEFrame句柄
Dim IEHwndArray As New ArrayList
IEHwndArray = findAllIe()
'如果IEFrame数量为0,那么就立即返回空IEFrameTabHwndArray
If IEHwndArray.Count = 0 Then Return IEFrameTabHwndArray
Dim result As Integer
'需要查找类名"FrameTab"
Dim ieClass As String = "Frame Tab"
'循环获得FrameTab Hwnd
For i As Integer = 0 To IEHwndArray.Count - 1
Try
'从IEFrame句柄获得它下面的第一个FrameTab句柄
result = FindWindowEx(CType(IEHwndArray(i), Integer), 0, ieClass, Nothing)
Do While result <> 0
'记录IE窗口的Hwnd,一直传递下去
IEframeTabHwnd.IEhwnd = CType(IEHwndArray(i), Integer)
'记录当前FrameTab窗口的Hwnd,一直传递下去
IEframeTabHwnd.FTabhwnd = result
'用于记录IE_Server的窗口句柄,暂时用不上
IEframeTabHwnd.Ie_SHwnd = 0
IEFrameTabHwndArray.Add(IEframeTabHwnd)
'从IEFrame句柄获得它下面的下一个FrameTab句柄,直到返回0
result = FindWindowEx(CType(IEHwndArray(i), Integer), result, ieClass, Nothing)
Loop
Catch ex As Exception
Continue For
End Try
Next
Return IEFrameTabHwndArray
End Function
测试用的调用代码:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
Dim listIe As New ArrayList
listIe = getIEFrameTab()
If listIe.Count > 0 Then
For i As Integer = 0 To listIe.Count - 1
ListBox1.Items.Add(CType(listIe.Item(i), IEWindowHwnd).FTabhwnd)
Next
End If
End Sub
由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。
学习更多vb.net知识,请参看vb.net教程 目录
————————————————
版权声明:本文为CSDN博主「VB.Net」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。