• <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

            如何對(duì)webbrowser和IE編程(五)

            目錄(?)[-]

            1. 自動(dòng)化 Internet Explorer
              1. 使用VB
                1. VbAutoIE.bas

            自動(dòng)化 Internet Explorer

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

            自動(dòng)化IE很容易。你建立一個(gè)簡(jiǎn)單的應(yīng)用啟動(dòng)一個(gè)IE實(shí)例,然后使用控制webbrowser的途徑-IWebBrowser2 接口來控制IE實(shí)例。

            提醒


            術(shù)語(yǔ)自動(dòng)化(automation真實(shí)的含義是通過自動(dòng)化接口-- IDispatch.控制一個(gè)COM對(duì)象。但是在此是指控制IE的技術(shù),你不需要直接通過IDispatch

            使用VB

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

            啟動(dòng)一個(gè)Standard EXE 工程,選擇References 菜單項(xiàng). 引用對(duì)話框展開如Figure 6-19:

            Figure 6-19. References dialog box.

            滾動(dòng)下拉,選中 Microsoft Internet Controls 檢查框,點(diǎn)擊OK 。加入一個(gè)命令按鈕到窗體,命名為btnStart, 修改標(biāo)題為 Start IE5. 然后雙擊加入click事件代碼。

            當(dāng)用戶點(diǎn)擊Start IE5 按鈕, 你想應(yīng)用程序啟動(dòng)一個(gè)Internet Explorer 5實(shí)例. 先建立一個(gè)類型為 InternetExplorer 的全局變量. 命名為InternetExplorer1.

            現(xiàn)在, 在btnStart的Click 事件中, 加入如果上一個(gè)實(shí)例沒有創(chuàng)建就創(chuàng)建新IE實(shí)例的代碼。你可以使用CreateObject 或者Vb的New 關(guān)鍵字.如下:

             

            Set InternetExplorer1 = New InternetExplorer

             

            該代碼創(chuàng)建一個(gè)新實(shí)例,但是實(shí)例是隱藏的,要顯示該實(shí)例,設(shè)定Visible 屬性為 True, 如下:

             

            InternetExplorer1.Visible = True

             

            現(xiàn)在你需要導(dǎo)航到某個(gè)web頁(yè),你可以如下調(diào)用InternetExplorer 對(duì)象的Navigate方法, 如下:

             

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

             

            至此,整個(gè)Vb的自動(dòng)化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

             

            運(yùn)行應(yīng)用程序看到IE啟動(dòng)了! 新的IE實(shí)例將被啟動(dòng)導(dǎo)航到MS的主頁(yè)。者不太困難,是不是?現(xiàn)在讓我們加入一些實(shí)在的較酷的特征允許你控制你自己創(chuàng)建的IE實(shí)例。

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

             

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

            現(xiàn)在如下表設(shè)定每一個(gè)控件的屬性如表6-8.創(chuàng)建4個(gè)選項(xiàng)組,每一個(gè)包含 一個(gè)顯示和一個(gè)隱藏選項(xiàng)按鈕如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 對(duì)象的代碼控制瀏覽器的用戶接口??纯辞鍐?-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, 當(dāng)表單被裝載,  InternetExplorer1 對(duì)象設(shè)定為Nothing.當(dāng)Start IE5 按鈕被點(diǎn)擊, 我們檢查確信沒有上一個(gè)實(shí)例啟動(dòng),如果啟動(dòng)了我們直接返回。

            如果上一實(shí)例沒有啟動(dòng),我們采用關(guān)鍵字New 創(chuàng)建一個(gè)新實(shí)例。然后我們檢查選項(xiàng)組的狀態(tài).我們依據(jù)選項(xiàng)當(dāng)前值進(jìn)行IS屬性的設(shè)置。然后設(shè)置Visible 屬性為 True. 最后我們使用Navigate 方法導(dǎo)航到MS的主頁(yè).

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

            導(dǎo)航

            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            隨筆分類

            文章分類

            文章檔案

            搜索

            最新評(píng)論

            久久er国产精品免费观看8| 色婷婷综合久久久久中文一区二区| 久久受www免费人成_看片中文| 久久免费高清视频| 久久久久夜夜夜精品国产| 久久99国产综合精品免费| 香蕉久久av一区二区三区| 久久综合给合久久国产免费| 亚洲午夜久久久久久久久久| 亚洲AV成人无码久久精品老人| 日韩精品久久无码人妻中文字幕| 亚洲色婷婷综合久久| 久久精品国产网红主播| 狠色狠色狠狠色综合久久| 91精品国产91热久久久久福利 | 久久无码国产专区精品| 无码人妻久久一区二区三区蜜桃| 久久精品国产精品亚洲精品| 久久精品国产男包| 久久99国产精品99久久| 久久久久九国产精品| 97香蕉久久夜色精品国产| 精品久久久久久无码专区不卡 | 亚洲国产综合久久天堂| 一本久久a久久精品综合香蕉| 国内精品伊人久久久久妇| 色欲综合久久躁天天躁蜜桃| 久久免费视频网站| 怡红院日本一道日本久久 | 亚洲AV日韩精品久久久久| 久久精品中文无码资源站| 天天爽天天爽天天片a久久网| 久久免费大片| 成人国内精品久久久久一区| 欧美成a人片免费看久久| 国产∨亚洲V天堂无码久久久| 久久久久婷婷| 99久久综合狠狠综合久久| 久久夜色精品国产噜噜麻豆 | 久久亚洲精品中文字幕三区| 婷婷久久五月天|