• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            yehao's Blog

            如何對webbrowser和IE編程(五)

            目錄(?)[-]

            1. 自動化 Internet Explorer
              1. 使用VB
                1. VbAutoIE.bas

            自動化 Internet Explorer

            自動化打開了開發基于web應用的世界。 它允許你使用VB或者VC定制成熟的應用。自動化的好處:通過屬性和方法可以改變IE的外觀;你可以提供諸如導航條等用戶接口以便控制用戶的導航。

            自動化IE很容易。你建立一個簡單的應用啟動一個IE實例,然后使用控制webbrowser的途徑-IWebBrowser2 接口來控制IE實例。

            提醒


            術語自動化(automation真實的含義是通過自動化接口-- IDispatch.控制一個COM對象。但是在此是指控制IE的技術,你不需要直接通過IDispatch

            使用VB

            前面已經介紹了如何五分鐘在VB中使用webbrowser來創建全功能的瀏覽器應用. 你也可以大致使用此時間用VB自動化IE。讓我們開始。

            啟動一個Standard EXE 工程,選擇References 菜單項. 引用對話框展開如Figure 6-19:

            Figure 6-19. References dialog box.

            滾動下拉,選中 Microsoft Internet Controls 檢查框,點擊OK 。加入一個命令按鈕到窗體,命名為btnStart, 修改標題為 Start IE5. 然后雙擊加入click事件代碼。

            當用戶點擊Start IE5 按鈕, 你想應用程序啟動一個Internet Explorer 5實例. 先建立一個類型為 InternetExplorer 的全局變量. 命名為InternetExplorer1.

            現在, 在btnStart的Click 事件中, 加入如果上一個實例沒有創建就創建新IE實例的代碼。你可以使用CreateObject 或者Vb的New 關鍵字.如下:

             

            Set InternetExplorer1 = New InternetExplorer

             

            該代碼創建一個新實例,但是實例是隱藏的,要顯示該實例,設定Visible 屬性為 True, 如下:

             

            InternetExplorer1.Visible = True

             

            現在你需要導航到某個web頁,你可以如下調用InternetExplorer 對象的Navigate方法, 如下:

             

            InternetExplorer1.Navigate "http://www.microsoft.com/"

             

            至此,整個Vb的自動化IE的源代碼看起來如下:

             

            Option Explicit
            Dim InternetExplorer1 As InternetExplorer
             

             

            Private Sub btnStart_Click()
               ' Only create a new instance of Internet Explorer
               ' if one hasn't already been created.
               '
               If Not InternetExplorer1 Is Nothing Then
                  Exit Sub
               End If
             

             

               Set InternetExplorer1 = New InternetExplorer
               
               ' Make Internet Explorer visible and navigate
               ' to Microsoft's home page.
               '
               InternetExplorer1.Visible = True
               InternetExplorer1.Navigate "http://www.microsoft.com/"
            End Sub
             

             

            Private Sub Form_Load()
               Set InternetExplorer1 = Nothing
            End Sub

             

            運行應用程序看到IE啟動了! 新的IE實例將被啟動導航到MS的主頁。者不太困難,是不是?現在讓我們加入一些實在的較酷的特征允許你控制你自己創建的IE實例。

            首先保存工程為 VbAutoIE.vbp, 且保存你的表單 VbAutoIE.frm. 然后加入一些控制到你的表單,如圖Figure 6-20. 這些允許你顯示或者隱藏IE中不同的用戶接口特征如地址欄、菜單條、狀態條和工具條等。你也可以加入文字到狀態條。

             

            Figure 6-20. Visual Basic form with controls to customize the Internet Explorer user interface.

            現在如下表設定每一個控件的屬性如表6-8.創建4個選項組,每一個包含 一個顯示和一個隱藏選項按鈕如Figure 6-20.

            Table 6-8. Control Properties for a Visual Basic Program Automating Internet Explorer

             

            Control

             

             

             

             

            Properties

             

             

             

             

            Frame1-4

             

             

             

             

            Captions = "AddressBar", "MenuBar", "StatusBar ", and "ToolBar", respectively

             

             

             

             

            Hide Option Buttons

             

             

             

             

            Caption = "Hide"; Index = 0; Value = False; Names = optAddrBaroptMenuBar,optStatusBar, and optToolBar, respectively

             

             

             

             

            Show Option Buttons

             

             

             

             

            Caption = "Show"; Index = 1; Value = True; Names = optAddrBaroptMenuBar,optStatusBar, and optToolBar, respectively

             

             

             

             

            Label

             

             

             

             

            Caption = "Status Text"

             

             

             

             

            TextBox

             

             

             

             

            Name = txtStatusText. Remove the default text for the Text property

             

             

             

             

            CommandButton

             

             

             

             

            Caption = "Change"; Name = btnChange

             

             

             

             

             

            加入控制InternetExplorer 對象的代碼控制瀏覽器的用戶接口??纯辞鍐?-1

            Listing 6-1.

             

            VbAutoIE.bas

            Option Explicit
            Dim InternetExplorer1 As InternetExplorer
            Const HideBar = 0
            Const ShowBar = 1
            Private Sub btnChange_Click()
               On Error Resume Next
               InternetExplorer1.StatusText = txtStatusText.Text
            End Sub
             

             

            Private Sub btnStart_Click()
               ' Only create a new instance of Internet Explorer
               ' if one hasn't already been created.
               '
               If Not InternetExplorer1 Is Nothing Then
                  Exit Sub
               End If
               
               Set InternetExplorer1 = New InternetExplorer
               
               ' Set the user interface features to match the
               ' entries specified by the user.
               '
               If optAddrBar(ShowBar).Value = True Then
                  InternetExplorer1.AddressBar = True
               Else
                  InternetExplorer1.AddressBar = False
               End If
               
               If optMenuBar(ShowBar).Value = True Then
                  InternetExplorer1.MenuBar = True
               Else
                  InternetExplorer1.MenuBar = False
               End If
               
               If optToolBar(ShowBar).Value = True Then
                  InternetExplorer1.ToolBar = True
               Else
                  InternetExplorer1.ToolBar = False
               End If
             

             

               If optStatusBar(ShowBar).Value = True Then
                  InternetExplorer1.StatusBar = True
               Else
                  InternetExplorer1.StatusBar = False
               End If
               
               ' Make Internet Explorer visible and navigate
               ' to Microsoft's home page.
               '
               InternetExplorer1.Visible = True
               InternetExplorer1.Navigate "http://www.microsoft.com/"
            End Sub
             

             

            Private Sub Form_Load()
               Set InternetExplorer1 = Nothing
            End Sub
             

             

            Private Sub Form_Unload(Cancel As Integer)
               On Error Resume Next
               InternetExplorer1.Quit
            End Sub
             

             

            Private Sub optAddrBar_Click(Index As Integer)
               On Error Resume Next
               InternetExplorer1.AddressBar = CBool(Index)
            End Sub
             

             

            Private Sub optMenuBar_Click(Index As Integer)
               On Error Resume Next
               InternetExplorer1.MenuBar = CBool(Index)
            End Sub
             

             

            Private Sub optStatusBar_Click(Index As Integer)
               On Error Resume Next
               InternetExplorer1.StatusBar = CBool(Index)
            End Sub
             

             

            Private Sub optToolBar_Click(Index As Integer)
               On Error Resume Next
               InternetExplorer1.ToolBar = Index
            End Sub

             

            在清單6-1, 當表單被裝載,  InternetExplorer1 對象設定為Nothing.當Start IE5 按鈕被點擊, 我們檢查確信沒有上一個實例啟動,如果啟動了我們直接返回。

            如果上一實例沒有啟動,我們采用關鍵字New 創建一個新實例。然后我們檢查選項組的狀態.我們依據選項當前值進行IS屬性的設置。然后設置Visible 屬性為 True. 最后我們使用Navigate 方法導航到MS的主頁.

            posted on 2012-09-22 21:44 厚積薄發 閱讀(387) 評論(0)  編輯 收藏 引用 所屬分類: Windows編程

            導航

            <2025年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            統計

            常用鏈接

            留言簿

            隨筆分類

            文章分類

            文章檔案

            搜索

            最新評論

            久久人人爽人人爽人人av东京热 | 99久久精品国产一区二区蜜芽| 久久精品国产亚洲av影院| 久久久久久无码Av成人影院| 精品一区二区久久久久久久网站| 国产激情久久久久影院老熟女免费| 久久天天婷婷五月俺也去| 无码人妻久久一区二区三区免费 | 久久婷婷五月综合成人D啪| 狠狠色丁香久久婷婷综合五月 | 99久久婷婷国产一区二区| 久久亚洲AV无码精品色午夜 | 亚洲国产成人久久综合野外| 久久国产免费观看精品3| 精品国产91久久久久久久a| 无遮挡粉嫩小泬久久久久久久 | 婷婷久久综合九色综合98| 欧美麻豆久久久久久中文| 久久精品无码一区二区无码| 久久午夜无码鲁丝片午夜精品| 久久天天躁狠狠躁夜夜96流白浆| 性做久久久久久久久| 久久精品国产亚洲麻豆| 无码人妻精品一区二区三区久久久| 日韩欧美亚洲综合久久影院d3| 久久综合亚洲色HEZYO社区| 久久精品无码一区二区三区免费| 狠狠88综合久久久久综合网| 亚洲国产欧美国产综合久久| 久久久这里有精品| 亚洲AV伊人久久青青草原| 国产精品VIDEOSSEX久久发布| 久久久久久亚洲Av无码精品专口| 亚洲中文精品久久久久久不卡| 亚洲国产成人久久综合碰| 亚洲精品99久久久久中文字幕| 久久综合色区| 亚洲中文字幕无码久久精品1| 日韩人妻无码精品久久免费一| 久久精品aⅴ无码中文字字幕重口 久久精品a亚洲国产v高清不卡 | 人妻精品久久无码专区精东影业|