vb.net 教程 20-3 控制Ie浏览器 5

本文介绍了一种通过VB.NET编程语言获取Internet Explorer浏览器InternetExplorer_Server句柄的方法。具体步骤包括从FrameTab开始,逐步获取TabWindowClass、shellDocObjectView直至InternetExplorer_Server的句柄。
摘要由CSDN通过智能技术生成
四、获得Ie窗口 Internet Explorer_Server 句柄

IEFrame->Frame Tab->TabWindowClass->shell DocObject View->Internet Explorer_Server

上一小节获得了 Frame Tab 的句柄,本节继续获得 Internet Explorer_Server 句柄
需要注意的是,从Frame Tab之后,从TabWindowClass 到 Internet Explorer_Server 获得的都是单个的句柄。

具体代码如下:
    ''' <summary>
    ''' 获得IE的Internet Explorer_Server
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function getIEServer() As ArrayList
        Dim IEServerArray As New ArrayList

        Dim IEServerHwnd As IEWindowHwnd
        '获得所有的FrameTab句柄
        Dim IEFrameTabHwndArray As New ArrayList
        IEFrameTabHwndArray = getIEFrameTab()
        '如果FrameTab数量为0,那么就立即返回空IEServerArray
        If IEFrameTabHwndArray.Count = 0 Then Return IEServerArray

        '循环FrameTab最终获得Internet Explorer_Server 句柄
        For i As Integer = 0 To IEFrameTabHwndArray.Count - 1
            Try
                'TabWindowClass
                Dim TWCHwnd As Integer
                TWCHwnd = FindWindowEx(CType(IEFrameTabHwndArray(i), IEWindowHwnd).FTabhwnd, 0, "TabWindowClass", Nothing)
                If TWCHwnd = 0 Then
                    Continue For
                End If
                'shell DocObject View
                Dim SDVHwnd As Integer
                SDVHwnd = FindWindowEx(TWCHwnd, 0, "shell DocObject View", Nothing)
                If SDVHwnd = 0 Then
                    Continue For
                End If
                'Internet Explorer_Server
                Dim IESHwnd As Integer
                IESHwnd = FindWindowEx(SDVHwnd, 0, "Internet Explorer_Server", Nothing)
                If IESHwnd <> 0 Then
                    '记录IE窗口的Hwnd,一直传递下去
                    IEServerHwnd.IEhwnd = CType(IEFrameTabHwndArray(i), IEWindowHwnd).IEhwnd
                    '记录Internet Explorer_Server窗口的Hwnd
                    IEServerHwnd.Ie_SHwnd = IESHwnd
                    IEServerHwnd.FTabhwnd = CType(IEFrameTabHwndArray(i), IEWindowHwnd).FTabhwnd
                    IEServerArray.Add(IEServerHwnd)
                End If

            Catch ex As Exception
                Continue For
            End Try
        Next

        Return IEServerArray
    End Function

测试代码如下:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ListBox1.Items.Clear()

        Dim listIe As New ArrayList
        listIe = getIEServer()
        If listIe.Count > 0 Then
            For i As Integer = 0 To listIe.Count - 1
                ListBox1.Items.Add(CType(listIe.Item(i), IEWindowHwnd).Ie_SHwnd)
            Next
        End If
    End Sub

运行结果如下:
3

注意:spy++中是用十六进制显示的。


由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。

学习更多vb.net知识,请参看vb.net 教程 目录


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值