none
如何取得 IE7 or 8 分頁頁籤的 Focus 狀態 RRS feed

  • 一般討論

  • 下面我提供的程式,可以抓到目前 IE 的 HTML 內容
    在 IE6 時,沒有問題
    但如果在 IE7 or IE8 時,
    如果有多個分頁,就會出現好幾個頁面的 HTML 內容

    問題來了:
    只要讀取 IE 正在瀏覽的分頁中 HTML 內容
    而不要抓到全部的

    請問,要如何判斷哪個分頁是正在瀏覽中的狀態呢?
    謝謝。
    '先引用
    'Microsoft Internet Controls (shdocvw.dll)
    'Microsoft HTML Object Library (MSHTML.TLB)
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
        (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Private Sub Command1_Click()
        Dim IEhWnd2 As Long
        IEhWnd2 = FindWindow("IEFrame", vbNullString)
        If Not IEhWnd2 = 0 Then
            Dim objIE As WebBrowser_V1
            Dim IE2 As InternetExplorer
            Dim dWinFolder As New ShellWindows
            Dim objDoc As MSHTML.HTMLDocument
            Dim HTML As String
            HTML = ""
            For Each objIE In dWinFolder
                If objIE.Parent.hWnd = IEhWnd2 Then
                    Set IE2 = objIE.Parent
                    Set objDoc = IE2.document
                    Dim I As Integer
                    For I = 0 To objDoc.All.length - 1
                        HTML = HTML & objDoc.All(I).outerHTML & vbCrLf
                        If objDoc.All(I).tagName = "HTML" Then Exit For
                    Next
                End If
                HTML = HTML & vbCrLf & "不同頁面資料..." & vbCrLf & vbCrLf
            Next
            Open "C:\HTML.htm" For Output As #1
            Print #1, HTML
            Close #1
            Shell "notepad.exe c:\html.htm", vbMaximizedFocus
            Set objDoc = Nothing
            Set dWinFolder = Nothing
            Set objIE = Nothing
            Set IE2 = Nothing
        End If
    End Sub
    
    
    

    2009年6月11日 上午 02:30