|
論壇說明 |
歡迎您來到『史萊姆論壇』 ^___^ 您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的! 請點擊這裡:『註冊成為我們的一份子!』 |
|
主題工具 | 顯示模式 |
2008-09-27, 05:56 PM | #1 |
註冊會員
|
疑問 - 如何在URLDownloadToFile下載時得知進度
-------------------- 閱讀本主題的最佳解答 -------------------- 爬了不少文始終不知道該如何實做IBindStatusCallback這介面 特地來問問看,是否有誰會使用 |
送花文章: 362,
|
2008-09-29, 01:24 AM | #4 (permalink) |
註冊會員
|
大部份的人都用winsock, inet來設計 比較少人用URLDownloadToFile 既然你inet不熟 ,我就 回答這個URLDownloadToFile 表單先加一個 進度條ProgressBar1 一個Label1 主要是在表單加上 一行Implements olelib.IBindStatusCallback 和以下2個事件 就可以了. 語法:
Implements olelib.IBindStatusCallback Private Function StartTheStinkinDownLoad(ByVal File2DownLoad As String, ByVal File2Save As String) As Boolean Dim DownLoadResult As Long DownLoadResult = olelib.URLDownloadToFile(Nothing, File2DownLoad, File2Save, 0, Me) StartTheStinkinDownLoad = (DownLoadResult = olelib.S_OK) End Function Private Sub IBindStatusCallback_OnProgress(ByVal ulProgress As Long, ByVal ulProgressMax As Long, ByVal ulStatusCode As olelib.BINDSTATUS, ByVal szStatusText As Long) On Error GoTo BadDeal If ulProgressMax <= 0 Then Exit Sub ProgressBar1.Max = CSng(ulProgressMax) ' set the progress bar's max value after it is known for sure ProgressBar1.Value = CSng(ulProgress) ' set the current level of progress DoEvents 'force a refresh... even though this slows things down Exit Sub BadDeal: Form1.Text3.Text = Form1.Text3.Text & "下載出錯: " & ulProgress & "/" & ProgressBar1.Value & "/" & ulProgressMax & "/" & ProgressBar1.Max & vbCrLf Resume Next End Sub 語法:
Public Function ShowDownLoad(FileList As String, Optional Owner As Object) Dim i, X As Integer i = Split(FileList, ",") Me.Print "正在下載... 請稍候..." Label1.Caption = "檢查複製緩存..." If IsMissing(Owner) = False Then Me.Show Else Me.Show vbModeless, Owner End If Me.Refresh Dim File2DownLoad As String, File2Save As String, DeleteCache As Boolean, TopLimit As Integer, TempDelete As String, OffSet As Integer TopLimit = (UBound(i) - 2) / 3 OffSet = 0 For X = 0 To TopLimit File2DownLoad = i(OffSet) File2Save = i(OffSet + 1) TempDelete = i(OffSet + 2) If TempDelete = "1" Then DeleteCache = True Else DeleteCache = False End If OffSet = OffSet + 3 ProgressBar1.Value = 0 Form1.Text3.Text = Form1.Text3.Text & "開始下載文件..." & vbCrLf Form1.Text3.Text = Form1.Text3.Text & File2DownLoad & vbCrLf If DeleteCache Then If DeleteUrlCacheEntry(File2DownLoad) = 1 Then Form1.Text3.Text = Form1.Text3.Text & "找到上次下載緩存文件刪除..." & vbCrLf Else Form1.Text3.Text = Form1.Text3.Text & "沒有緩存文件存在" & vbCrLf End If End If Label1.Caption = File2DownLoad If StartTheStinkinDownLoad(File2DownLoad, File2Save) Then Form1.Text3.Text = Form1.Text3.Text & "文件下載完畢: " & File2DownLoad & vbCrLf & vbCrLf ShowDownLoad = True Else Form1.Text3.Text = Form1.Text3.Text & "文件下載失敗!" & vbCrLf ShowDownLoad = False End If Next Form1.Text3.Text = Form1.Text3.Text & "結束下載文件..." & vbCrLf Unload Me Set frmDnLoad = Nothing End Function Private Sub Command1_Click() Dim FileList As String FileList = Text1.Text & "," & Text2.Text & "," & "1" Call frmDnLoad.ShowDownLoad(FileList, Me) End Sub 此帖於 2008-09-29 01:49 AM 被 飛行船大大 編輯. |
送花文章: 175,
|
向 飛行船大大 送花的會員:
|
rank (2008-09-29)
感謝您發表一篇好文章 |
2008-09-29, 06:02 AM | #6 (permalink) |
註冊會員
|
我找到元件了,可以跑了
可是問題來了,我的進度表那裡一直弄不好,能否幫我看看 一直常發生溢位和錯誤 語法:
Implements olelib.IBindStatusCallback Private Function StartTheStinkinDownLoad(ByVal File2DownLoad As String, ByVal File2Save As String) As Boolean Dim DownLoadResult As Long DownLoadResult = olelib.URLDownloadToFile(Nothing, File2DownLoad, File2Save, 0, Me) StartTheStinkinDownLoad = (DownLoadResult = olelib.S_OK) End Function Private Sub IBindStatusCallback_GetBindInfo(grfBINDF As olelib.BINDF, pbindinfo As olelib.BINDINFO) End Sub Private Function IBindStatusCallback_GetPriority() As Long End Function Private Sub IBindStatusCallback_OnDataAvailable(ByVal grfBSCF As olelib.BSCF, ByVal dwSize As Long, pformatetc As olelib.FORMATETC, pStgmed As olelib.STGMEDIUM) End Sub Private Sub IBindStatusCallback_OnLowResource(ByVal reserved As Long) End Sub Private Sub IBindStatusCallback_OnObjectAvailable(riid As olelib.UUID, ByVal pUnk As stdole.IUnknown) End Sub Private Sub IBindStatusCallback_OnProgress(ByVal ulProgress As Long, ByVal ulProgressMax As Long, ByVal ulStatusCode As olelib.BINDSTATUS, ByVal szStatusText As Long) ProgressBar1.Min = 0 ProgressBar1.Max = 100 If ulProgressMax <> 0 Then ProgressBar1.Value = CInt(100 * (ulProgress / ulProgressMax)) End If If ulProgressMax <> 0 Then Debug.Print ulProgress Debug.Print ulProgressMax Debug.Print ulProgress / ulProgressMax End If End Sub Private Sub Command1_Click() StartTheStinkinDownLoad "http://www.google.com.tw/", "C:/abc.txt" End Sub Private Sub IBindStatusCallback_OnStartBinding(ByVal dwReserved As Long, ByVal pib As olelib.IBinding) End Sub Private Sub IBindStatusCallback_OnStopBinding(ByVal hresult As Long, ByVal szError As Long) End Sub |
送花文章: 362,
|
2008-09-29, 10:58 PM | #8 (permalink) |
註冊會員
|
ProgressBar1.Value = CInt(100 * (ulProgress / ulProgressMax))
是這一行會發生錯誤,照理說ulProgressMax應該會比ulProgress大 但事實跑起來並不然,使得我的ProgressBar1.Value 的值超出100而超出範圍造成錯誤 而且從頭到尾的數值改變只有變動一次...我把我Debug 印的PO上來好了 [1] Progress event received: 0 of 0, StatusCode: 34 [2] Progress event received: 0 of 0, StatusCode: 1 [3] Progress event received: 0 of 0, StatusCode: 2 [4] Progress event received: 0 of 0, StatusCode: 11 [5] Progress event received: 0 of 0, StatusCode: 24 [6] Progress event received: 0 of 0, StatusCode: 13 [7] Progress event received: 6779 of 3115, StatusCode: 4 [8] Progress event received: 6779 of 3115, StatusCode: 14 [9] Progress event received: 6779 of 3115, StatusCode: 6 以上就是我Debug印出來的狀態 |
送花文章: 362,
|
|
|
相似的主題 | ||||
主題 | 主題作者 | 討論區 | 回覆 | 最後發表 |
如何在w2k底下看下載的DVDrip?(無DVDRom) | darren52d | 一般電腦疑難討論區 | 2 | 2003-07-23 06:52 AM |
如何讓ftp軟體在下載時有續傳的功能 | 左非 | 一般電腦疑難討論區 | 0 | 2003-03-08 11:27 PM |
請問IE如何取消下載的時間限制,或更改下載時間限制? | vivivi | 軟體應用問題討論區 | 4 | 2003-02-22 03:33 AM |