vbactivex控件:用vb6的ActiveX控件实现异步下载-vb教程来源: 发布时间:星期四, 2009年2月12日 浏览:388次 评论:0
6 序:笔者(airon,softWorker)注意到 具体思路方法: 1.新建 2.选择工程菜单 3.更改Activex用户Control控件 4.输入代码:(在用户Control控件 Option Explicit Event DownloadProgress(CurBytes As Long, MaxBytes As Long, SaveFile As String) Event DownloadError(SaveFile As String) Event DownloadComplete(MaxBytes As Long, SaveFile As String) ´Public downStat As Boolean Public Function CancelAsyncRead _disibledevent=>´ Exit Sub ´ End If ´ Static Cs As Integer ´ If Cs > 2 Then Cs = 0 ´ UserControl.Picture = P1(Cs).Picture ´ Cs = Cs + 1 ´ DoEvents ´End Sub Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty) _disibledevent=> f = AsyncProp.Value Open AsyncProp.PropertyName For Binary Access Write As #fn Put #fn, , f Close #fn Else RaiseEvent DownloadError(AsyncProp.PropertyName) End If RaiseEvent DownloadComplete(CLng(AsyncProp.BytesMax), AsyncProp.PropertyName) downStat = False End Sub Private Sub UserControl_AsyncReadProgress(AsyncProp As AsyncProperty) _disibledevent=> End If End Sub ´Private Sub UserControl_Resize ´ SizeIt ´End Sub Public Sub BeginDownload(url As String, SaveFile As String) _disibledevent=> UserControl.AsyncRead url, vbAsyncTypeByteArray, SaveFile, vbAsyncReadForceUpdate Timer1.Enabled = True Exit Sub ErrorBeginDownload: downStat = False MsgBox Err & \"开始下载数据失败!\" _ & vbCrLf & vbCrLf & \" End Sub ´Public Sub SizeIt ´ _disibledevent=>´ .Height = ScaleY(32, vbPixels, vbTwips) ´ End With ´ Exit Sub ´ErrorSizeIt: ´End Sub ´Public Sub kill ´ downStat = False ´ Dim m As AsyncProperty ´ MsgBox m.Value ´End Sub ----------------------------------------------------- 本文采取VB6中OCX中 用到 AsyncRead(异步读取) 文中带注解 ----------------------------------------------------- 4.关闭用户Control控件 5.这时你会看到在左边 6.在窗体上添加 7.在窗体 Form1 Option Explicit ´ ´ ´ ´ ´ ´ ´ Private Sub Command1_Click Downloader1.BeginDownload url, SaveFile ´请把 URL 替代为 Http://文件路径 ´请把 savefile 替代为下载到本地文件 End Sub Private Sub Downloader1_DownloadComplete(MaxBytes As Long, SaveFile As String) MsgBox \"文件下载完成 End Sub Private Sub Downloader1_DownloadError(SaveFile As String) MsgBox \"下载发生 End Sub Private Sub Downloader1_DownloadProgress(CurBytes As Long, MaxBytes As Long, SaveFile As String) ´在这里添加进度第 End Sub 最后申明: 本文为 airon,softWorker 原作 0
相关文章
读者评论发表评论 |
