| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 576 人关注过本帖
标题:请教进度条与下载进度如何匹配问题
只看楼主 加入收藏
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:295
专家分:38
注 册:2010-12-23
结帖率:58.02%
收藏
已结贴  问题点数:10 回复次数:5 
请教进度条与下载进度如何匹配问题
下载一个文件用了DownloadFile()方法,因为文件有100M,下载时间超过一分钟,有什么办法显示成进度条,直观展现
下载代码
DECLARE LONG URLDownloadToFileA IN Urlmon LONG, STRING@, STRING@, LONG, LONG
DECLARE LONG DeleteUrlCacheEntry IN Wininet STRING@
DownloadFile("http://127.0.0.1:9880/chfs/shared/eqpt_file/202305/BF82%23%23%E5%8F%91%E7%A5%A8%E5%BC%80%E5%85%B7%E9%A1%B9%E7%9B%AE%E4%BF%A1%E6%81%AF%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF.mp4", "D:\myfolder\tt2.mp4")
搜索更多相关主题的帖子: 进度 进度条 LONG 匹配 STRING 
2023-05-09 19:59
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10607
专家分:43186
注 册:2014-5-20
收藏
得分:5 
VFP实现有困难
URLDownloadToFileA 最后一个参数可以实现进度条,通过创建一个IBindStatusCallback接口派生类实例的Onprogress事件来实现。

2023-05-09 21:21
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10607
专家分:43186
注 册:2014-5-20
收藏
得分:0 
可以试试用 wininet 或 winhttp 库API来实现,可以定义一定大小的缓冲来逐次读取要下载的文件。
2023-05-09 21:45
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:295
专家分:38
注 册:2010-12-23
收藏
得分:0 
回复 2楼 吹水佬
谢谢大佬回复,只是好高深,不懂如何实现,进度条显示下载进度
2023-05-09 22:16
dglhz
Rank: 2
来 自:东莞南城
等 级:论坛游民
威 望:1
帖 子:13
专家分:64
注 册:2022-5-7
收藏
得分:5 
木瓜老师的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


2023-05-10 02:14
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10607
专家分:43186
注 册:2014-5-20
收藏(1)
得分:0 
以下是引用laibinhua在2023-5-9 22:16:14的发言:

谢谢大佬回复,只是好高深,不懂如何实现,进度条显示下载进度

windows的API,用wininet简单的示例:用百分比显示进度
程序代码:
DECLARE long InternetOpenA       IN wininet string@,long,string@,string@,long
DECLARE long InternetOpenUrlA    IN wininet long,string@,string@,long,long,long
DECLARE long InternetCloseHandle IN wininet long
DECLARE long HttpQueryInfoA      IN wininet long,long,string@,long@,long@
DECLARE long InternetReadFile    IN wininet long,string@,long,long@

#define INTERNET_OPEN_TYPE_PRECONFIG    0
#define INTERNET_FLAG_RELOAD            0x80000000
#define HTTP_QUERY_CONTENT_LENGTH       5

TEXT TO url TEXTMERGE NOSHOW PRETEXT 7
https://v3-webc./4ecf1a395a7cc421c9f87cf1afc51d24/645b39ea/video/tos/cn/tos-cn-ve-15c001-alinc2/oUrk2vCdcAeyr9AtgQFwWJCDmfJWIEiEAABRaI/?a=6383&ch=5&cr=3&dr=0&lr=all&cd=0%7C0%7C0%7C3&cv=1&br=3331&bt=3331&cs=0&ds=3&ft=A-LhWQIw998xlYuECmD0P5q6xwApsmNP6vrKfwS4Nto0g3&mime_type=video_mp4&qs=0&rc=OWU7NWZmOGk8Omk5aGc8PEBpM2V0c3M5cjw1azMzNGkzM0BjLjMzYDQyNl8xM2EyYi9jYSNgNTJeMmRrLmFgLS1kLS9zcw%3D%3D&l=20230510131500ACA424248AFE660824E7&btag=e00038000
ENDTEXT
localFile = "d:\temp\test.mp4"

*    url [color=#808080]= "https://dl-cdn./sunlogin/windows/SunloginClientSOS_1.2.0.53483.exe"[/color]
*    localFile [color=#808080]= "d:\temp\SunloginClientSOS_1.2.0.53483.exe"[/color]

hInternet    = 0
hInternetUrl = 0
FOR _exit=0 TO 0
    hInternet = InternetOpenA("myHttpDownload", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0)
    IF hInternet == 0
        EXIT 
    ENDIF
    hInternetUrl = InternetOpenUrlA(hInternet, url, NULL, 0, INTERNET_FLAG_RELOAD, 0)
    IF hInternetUrl == 0
        EXIT 
    ENDIF
    nSize = 64
    cSize = SPACE(nSize)
    IF HttpQueryInfoA(hInternetUrl, HTTP_QUERY_CONTENT_LENGTH, @cSize, @nSize, 0) == 0
        EXIT 
    ENDIF
    cSize = LEFT(cSize, nSize)
    nSize = VAL(cSize)
    
    IF FILE(localFile)
        DELETE FILE (localFile)
    ENDIF
    fp = FCREATE(localFile)
    IF fp < 0
        EXIT
    ENDIF
    bufSize = 1024
    buf     = SPACE(bufSize+1)
    outSize = 0
    nCount  = 0
    tm = SECONDS()
    DO WHILE InternetReadFile(hInternetUrl,@buf,bufSize,@outSize)!=0 AND outSize>0
        FWRITE(fp, buf, outSize)
        nCount = nCount + outSize
        IF SECONDS()-tm > 1
            tm = SECONDS()
            ?? TRANSFORM(nCount)+" / "+cSize+ "  "+TRANSFORM(INT(100*nCount/nSize))+"%"+0h0D
        ENDIF 
    ENDDO
    ?? TRANSFORM(nCount)+" / "+cSize+ "  "+TRANSFORM(INT(100*nCount/nSize))+"%"+0h0D
    FCLOSE(fp)
ENDFOR
InternetCloseHandle(hInternet)
InternetCloseHandle(hInternetUrl)
2023-05-10 13:29
快速回复:请教进度条与下载进度如何匹配问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.054042 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved