#2
nbwww2023-11-12 11:42
|
FUNCTION URL_DOWNFILE
LPARAMETERS INTER_URL,LOCALFILE
ERASE (LocalFile)
DECLARE INTEGER InternetOpen IN wininet STRING, INTEGER, STRING, STRING, STRING
DECLARE INTEGER InternetOpenUrlW IN wininet INTEGER, STRING, STRING, INTEGER, INTEGER, INTEGER
DECLARE INTEGER HttpQueryInfo IN wininet INTEGER, INTEGER, STRING @, INTEGER @, INTEGER @
DECLARE INTEGER InternetReadFile IN wininet INTEGER, STRING @, INTEGER, INTEGER @
DECLARE INTEGER InternetCloseHandle IN wininet INTEGER
URL_OPEN = INTERNETOPEN("qm3d",1,CHR(0),CHR(0),0)
IF URL_OPEN = 0
RETURN -1
ENDIF
URL_SESSION = INTERNETOPENURLw(URL_OPEN,STRCONV(INTER_URL+CHR(0),5),null,2,16,0)
IF URL_SESSION = 0
= INTERNETCLOSEHANDLE(URL_OPEN)
RETURN -2
ENDIF
URL_FOPEN = FCREATE(LOCALFILE)
IF URL_FOPEN = -1
= INTERNETCLOSEHANDLE(URL_SESSION)
= INTERNETCLOSEHANDLE(URL_OPEN)
RETURN -3
ENDIF
URL_QUERYINFO = SPACE(32)
URL_QUERYINFOLEN = LEN(URL_QUERYINFO)
IF HTTPQUERYINFO(URL_SESSION,5,@URL_QUERYINFO,@URL_QUERYINFOLEN,0) = 1
URL_FILESIZE = VAL(LEFT(URL_QUERYINFO,URL_QUERYINFOLEN))
ELSE
URL_FILESIZE = -1
ENDIF
URL_SIZESUM = 0
URL_READBUFFER = REPLICATE(CHR(0),40960)
DO WHILE .T.
URL_READBYE = 0
IF INTERNETREADFILE(URL_SESSION,@URL_READBUFFER,40960,@URL_READBYE) = 1
IF URL_READBYE = 0
EXIT
ELSE
= FWRITE(URL_FOPEN,URL_READBUFFER,URL_READBYE)
ENDIF
URL_SIZESUM = URL_SIZESUM+URL_READBYE
IF URL_FILESIZE = -1
IF URL_SIZESUM > 0001048576
WAIT WINDOW NOWAIT "正在下载 "+STR(URL_SIZESUM/0001048576,10,3)+"M……" AT sROWS()/2,SCOLS()/2-30
ELSE
WAIT WINDOW NOWAIT "正在下载 "+STR(URL_SIZESUM/1024)+"K……" AT sROWS()/2,SCOLS()/2-30
ENDIF
ELSE
IF URL_SIZESUM > 0001048576
WAIT WINDOW NOWAIT "正在下载 "+STR(URL_SIZESUM/0001048576,10,3)+"M "+STR(URL_SIZESUM/URL_FILESIZE*100,6,2)+"%……" AT sROWS()/2,SCOLS()/2-30
ELSE
WAIT WINDOW NOWAIT "正在下载 "+STR(URL_SIZESUM/1024)+"K "+STR(URL_SIZESUM/URL_FILESIZE*100,6,2)+"%……" AT sROWS()/2,SCOLS()/2-30
ENDIF
ENDIF
ELSE
EXIT
ENDIF
ENDDO
WAIT CLEAR
= FCLOSE(URL_FOPEN)
= INTERNETCLOSEHANDLE(URL_SESSION)
= INTERNETCLOSEHANDLE(URL_OPEN)
RETURN URL_SIZESUM
ENDFUNC
[此贴子已经被作者于2023-11-12 12:43编辑过]