Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Dim file1 As String, file2 As String, percent As String
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then
DownloadFile = True
MsgBox "Download completato con seccesso", vbInformation, App.Title
avvia.Enabled = True
res.Enabled = True
perc.Enabled = True
url_file.Enabled = True
perc_file.Enabled = True
Else
DownloadFile = False
MsgBox "Errore durante il download", vbCritical, App.Title
avvia.Enabled = True
res.Enabled = True
perc.Enabled = True
url_file.Enabled = True
perc_file.Enabled = True
End If
End Function
Private Sub avvia_Click()
avvia.Enabled = False
res.Enabled = False
perc.Enabled = False
url_file.Enabled = False
perc_file.Enabled = False
ret = DownloadFile(url_file.Text, perc_file.Text)
End Sub
Private Sub Form_Load()
Me.Caption = App.Title & " vers. " & App.Major & "." & App.Minor & "." & App.Revision
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Not avvia.Enabled Then
MsgBox "Prima di uscire si consiglia di terminare il download in corso", vbExclamation, App.Title
Else
Unload Me
End
End If
End Sub
Private Sub perc_Click()
Dim percorso As String
If url_file.Text = "" Or url_file.Text = "http://" Then
MsgBox "Inserire prima il percorso del file da scaricare!", vbExclamation, App.Title
Exit Sub
End If
url_file.Enabled = False
Dialog.ShowOpen
If Dialog.FileTitle = "" Then
MsgBox "Non hai scelto un nome per il file", vbExclamation, App.Title
url_file.Enabled = True
Else
percorso = Trim$(url_file.Text)
percorso = Right$(percorso, 4)
perc_file.Text = Dialog.FileName & percorso
'file1 = FileLen(url_file.Text)
End If
End Sub
Private Sub res_Click()
url_file.Text = "http://"
perc_file.Text = ""
url_file.Enabled = True
End Sub
Private Sub url_file_Change()
perc_file.Text = ""
End Sub