木瓜老师的myfll可轻松实现
下例是简化了的例子,祥细请参阅myfll的帮助文件中的函数:DownFileX
PUBLIC oform1
oform1=NEWOBJECT("form1")
oform1.Show
RETURN
DEFINE CLASS form1 AS form
Height = 197
Width = 474
DoCreate = .T.
AutoCenter = .T.
Caption = "多线程下载示例 by木瓜"
Name = "form1"
ADD OBJECT label1 AS label WITH ;
Caption = "总大小:", ;
Height = 17, ;
Left = 36, ;
Top = 102, ;
Width = 84, ;
Name = "Label1"
ADD OBJECT text1 AS textbox WITH ;
Height = 23, ;
Left = 120, ;
Top = 101, ;
Width = 100, ;
Name = "Text1"
ADD OBJECT label2 AS label WITH ;
Caption = "当前下载大小:", ;
Height = 17, ;
Left = 228, ;
Top = 104, ;
Width = 84, ;
Name = "Label2"
ADD OBJECT text2 AS textbox WITH ;
Height = 23, ;
Left = 312, ;
Top = 102, ;
Width = 100, ;
Name = "Text2"
ADD OBJECT label5 AS label WITH ;
Caption = "myFll示例:", ;
Height = 17, ;
Left = 12, ;
Top = 12, ;
Width = 84, ;
Name = "Label5"
ADD OBJECT label6 AS label WITH ;
Caption = "正在下载向日葵Sos 32位", ;
Height = 17, ;
Left = 36, ;
Top = 36, ;
Width = 360, ;
Name = "Label6"
ADD OBJECT label7 AS label WITH ;
Caption = "可根据总大小和当前下载的大小来设计自己的进度条", ;
Height = 17, ;
Left = 36, ;
Top = 60, ;
Width = 360, ;
Name = "Label7"
PROCEDURE DownChange
Lparameters nHwnd,nMsg,nDownSize,nFileSize
If nDownSize=-1 and nFileSize=-1
Wait window "下载发生错误" nowait
Return
EndIf
If nDownSize=0 and nFileSize=-1
Wait window "服务器不支持文件大小" nowait
Return
EndIf
thisform.text1.Value=nFileSize
thisform.text2.Value=nDownSize
If nFileSize=nDownSize
MESSAGEbox("下载完成")
EndIf
PROCEDURE Init
Set Library To myfll
*每个线程需要一个单独的消息绑定
BindEvent(thisform.HWnd,9001,thisform,"DownChange")
*下面创建下载文件
DownFileX("https://dl-cdn.,"d:\001\SunloginClientSOS_1.2.0.53483.exe",thisform.HWnd,9001)
ENDPROC
PROCEDURE Destroy
Set Library To
ENDPROC
ENDDEFINE