三、获得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),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),result,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 教程 目录
原文链接:https://www.f2er.com/vb/256395.html