vb6引用vbRichClient5 下载对象 cDownloads 简单示例

Option Explicit
'vb6引用vbRichClient5.dll
'下载简单示例
'小噤 QQ574221329
Dim WithEvents 下载类 As cDownloads
Dim WithEvents 浏览器引擎 As cWebKit
Dim 下载列表() As String

Dim 全局字典 As Object, Fso As Object

Private Sub Command1_Click()

    Dim Obj

    For Each Obj In 全局字典
        下载类.Download (Obj)      '保存路径
    Next
    
End Sub

Private Sub Form_Load()
    '下载个数 = 6
    Set 全局字典 = CreateObject("Scripting.Dictionary")
    Set Fso = CreateObject("Scripting.FileSystemObject")

    全局字典("https://dl.360safe.com/360sd/360sd_std_5.0.0.8081C.exe") = -1
    全局字典("https://raw.githubusercontent.com/qq574221329/TlbbUpdate/master/README.md") = -1
    全局字典("https://raw.githubusercontent.com/qq574221329/TlbbUpdate/master/Bin.7z") = -1
    全局字典("https://raw.githubusercontent.com/qq574221329/TlbbUpdate/master/Begin20180427.7z.001") = -1
    全局字典("https://raw.githubusercontent.com/qq574221329/TlbbUpdate/master/Begin20180427.7z.002") = -1
    全局字典("https://raw.githubusercontent.com/qq574221329/TlbbUpdate/master/Begin20180427.7z.003") = -1
    全局字典("https://raw.githubusercontent.com/qq574221329/TlbbUpdate/master/Begin20180427.7z.004") = -1
    全局字典("https://raw.githubusercontent.com/qq574221329/TlbbUpdate/master/Begin20180427.7z.006") = -1
    全局字典("https://dldir1.qq.com/qqfile/qq/QQ9.0.2/23490/QQ9.0.2.exe") = -1
    全局字典("https://dl.360safe.com/setup.exe") = -1
    全局字典("http://down.360safe.com/se/360se9.1.0.420.exe") = -1
    
    Dim Obj
    
    For Each Obj In 全局字典
        全局字典(Obj) = Me.List1.ListCount
        Me.List1.AddItem Fso.GetFileName(Obj)      '保存路径
        
    Next

    'MsgBox Fso.GetFileName("https://raw.githubusercontent.com/qq574221329/TlbbUpdate/master/Begin20180427.7z.001")
    
    Set 浏览器引擎 = New cWebKit
    Set 下载类 = 浏览器引擎.Downloads
    'DeleteUrlCacheEntryW "https://raw.githubusercontent.com/qq574221329/TlbbUpdate/master/Bin.7z"
End Sub

Private Sub 下载类_DownloadComplete(DownloadObj As vbRichClient5.cDownload, ByVal ErrNum As Long, ErrString As String)
    'Debug.Print "下载类_DownloadComplete", Now(), DownloadObj.URL, ErrNum, ErrString
    'DownloadObj.SaveContentBytesToFile 这个方法用不了.改成写文件了
    Dim 二进制() As Byte
    二进制 = DownloadObj.GetContentData()
      
    Dim 保存路径 As String

    保存路径 = "c:\" & Fso.GetFileName(DownloadObj.URL) '保存路径
      
    Dim 可用文件号 As Long
    可用文件号 = FreeFile
      
    Open 保存路径 For Binary As #可用文件号
    Put #可用文件号, , 二进制
    Close #可用文件号
    Print 保存路径
    
    Me.List1.List(全局字典(DownloadObj.URL)) = "下载完成: " & Fso.GetFileName(DownloadObj.URL)

    DoEvents
End Sub
  
Private Sub 下载类_DownloadProgress(DownloadObj As vbRichClient5.cDownload, ByVal Percent As Single, ByVal StatusCode As Long, StatusDescription As String, StatusValue As String)
    '  Debug.Print "下载类_DownloadProgress", Now(), Percent, DownloadObj.URL, StatusCode, StatusDescription, StatusValue
    ' Debug.Print DownloadObj.URL
    ' Debug.Print Fso.GetFileName("https://raw.githubusercontent.com/qq574221329/TlbbUpdate/master/Begin20180427.7z.001")
    ' Debug.Print Fso.GetFileName(DownloadObj.URL)
    Me.List1.List(全局字典(DownloadObj.URL)) = "开始下载: " & Fso.GetFileName(DownloadObj.URL) & " " & Format$(Percent, "Percent")

    DoEvents
End Sub
  
Private Sub 下载类_DownloadStart(DownloadObj As vbRichClient5.cDownload)
    ' Debug.Print 全局字典(DownloadObj.URL), "下载类_DownloadStart", Now(), DownloadObj.URL

    Me.List1.List(全局字典(DownloadObj.URL)) = "等待下载: " & Fso.GetFileName(DownloadObj.URL)

    DoEvents
End Sub



©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值