¸Ã·½·¨²»ÐèҪʹÓÃAPI¼°µÚÈý·½¿Ø¼þ
ÕâÀïʹÓõÄÊÇVBµÄUserControl¿Ø¼þµÄAsyncRead·½·¨
²½ÖèÈçÏÂ:
1¡¢Ìí¼ÓÒ»¸öÓû§¿Ø¼þ£¬ÉèÖÃInvisibleAtRuntimeÊôÐÔΪtrue£¬Ä¿µÄÊÇÔËÐÐʱ¸Ã¿Ø¼þ²»ÏÔʾÓû§½çÃæ£¬¾ÍÏóTimer¿Ø¼þÒ»Ñù¡£
2¡¢µ½×Ô¶¨Òå¿Ø¼þµÄ´úÂë´°¿Ú£¬Ìí¼ÓÈçÏ´úÂë
Option Explicit
'ÏÂÔØ½á¹ûö¾Ù
Public Enum DownloadResults
eSUCCESS = 0 'ÏÂÔØ³É¹¦
eCONNECTERROR = 1 'Á¬½Ó´íÎó
eTRANSFERERROR = 2 'Êý¾Ý´«Êä´íÎó
eWRITEERROR = 3 '±£´æ±¾µØ´íÎó
eUserStop = 4 'ÖÐÖ¹
End Enum
'ÏÂÔØ½ø¶Èʼþ Identifier-ÏÂÔØ±êʶ,RecvdBytes-ÒÑÏÂÔØ×Ö½ÚÊý,MaxBytes-×Ü×Ö½ÚÊý,PassTimer-ÒÑÓÃÏÂÔØÊ±¼ä(Ãë)
Public Event DownloadProgress(Identifier As String, RecvdBytes As Long, MaxBytes As Long, PassTimer As Long)
'ÏÂÔØÍê³Éʼþ Identifier-ÏÂÔØ±êʶ,ccDownloadResults-ÏÂÔØ½á¹û,PassTimer-ÒÑÓÃÏÂÔØÊ±¼ä(Ãë)
Public Event DownloadComplete(Identifier As String, Result As DownloadResults, PassTimer As Long)
Dim FstrURL As String 'FTP ÏÂÔØ×Ö·û´®,º¬IP,¶Ë¿ÚºÅ,Óû§Ãû,ÃÜÂë,ÏÂÔØµÄÎļþ¼°Æä·¾¶
Dim FstrSaveFile As String 'ÏÂÔØµÄÎļþ±£´æÔÚ±¾µØµÄÎļþÃû¼°Æä·¾¶
Dim FstrIdentifier As String 'ÏÂÔØ±êʶ
Dim FlngStart As Long '¿ªÊ¼ÏÂÔØÊ±¼ä
'ÏÂÔØÎļþ
'strURL FTP ÏÂÔØ×Ö·û´®,º¬IP,¶Ë¿ÚºÅ,Óû§Ãû,ÃÜÂë,ÏÂÔØµÄÎļþ¼°Æä·¾¶
' ÐÎÈç ftp://Óû§Ãû:ÃÜÂë@FTPµØÖ·/Ŀ¼/Îļþ
'strSaveFile ±£´æÊ±µÄ±¾µØÎļþÃû
'strIdentifier ÏÂÔØ±êʶ,¿ÉÒÔͬʱÏÂÔØ¶à¸öÎļþ,ÒÀ¾Ý´Ë×Ö·û´®Çø±ðËùÏÂÔØµÄÎļþ
Public Sub DownLoad(ByVal strURL As String, ByVal strSaveFile As String, ByVal strIdentifier As String)
On Error GoTo ERRHAND
FstrURL = strURL
FstrSaveFile = strSaveFile
FstrIdentifier = strIdentifier
FlngStart = Timer
UserControl.AsyncRead strURL, vbAsyncTypeByteArray, strIdentifier, vbAsyncReadForceUpdate
Exit Sub
ERRHAND:
RaiseEvent DownloadComplete(strIdentifier, eCONNECTERROR, Timer - FlngStart)
End Sub
Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty)
On Error GoTo Errs
½ñÌìÔÚ×öVBÏîÄ¿µÄʱºò£¬Ê¹ÓÃÁËListBox¿Ø¼þÀ´»ñȡһЩÁбíÏÓÃÁ˲ŷ¢ÏÖûÓÐListViewºÃÓã¬ListViewÓÐItems£¨SelectItem£©¿ÉÒÔ¶¨Î»µ½µ±Ç°µÄÑ¡ÖÐÏ¶øListBoxûÓУ»ListViewÓÐTag¿ÉÒÔÉ趨ѡÖÐÏîµÄ±êʾ£¬ListBoxûÓС£ÉÏÍøÒ²ÕÒ²»µ½ÔÒò£¬ÖªµÀÈ¥ÔĶÁMSDNºÍ×Ô¼º²âÊÔ¡£
Ö®ºóÖÕÓÚÕÒµ½ÁËÎÊÌâµÄ¹Ø¼ü¡£
ʼþ1£ºÌí¼ÓListBoxÏ ......