📄 frmmain.frm
字号:
Height = 180
Left = 1920
TabIndex = 19
Top = 750
Width = 360
End
End
Begin VB.Frame Frame2
Caption = "下载类型"
Height = 1815
Left = 30
TabIndex = 4
Top = 360
Width = 3255
Begin VB.OptionButton optDlType
Caption = "保存到文件"
Height = 255
Index = 0
Left = 240
TabIndex = 11
Top = 240
Width = 2895
End
Begin VB.PictureBox Picture1
BorderStyle = 0 'None
Height = 675
Left = 480
ScaleHeight = 45
ScaleMode = 3 'Pixel
ScaleWidth = 177
TabIndex = 7
Top = 480
Width = 2655
Begin VB.OptionButton optDlToFile
Enabled = 0 'False
Height = 255
Index = 0
Left = 0
TabIndex = 10
Top = 15
Value = -1 'True
Width = 255
End
Begin VB.TextBox txtFilename
Enabled = 0 'False
Height = 285
Left = 240
TabIndex = 9
Text = "f:\myfile.rar"
Top = 0
Width = 2415
End
Begin VB.OptionButton optDlToFile
Caption = "Use temporary file"
Enabled = 0 'False
Height = 315
Index = 1
Left = 0
TabIndex = 8
Top = 360
Width = 2655
End
End
Begin VB.OptionButton optDlType
Caption = "下在到缓存"
Height = 255
Index = 1
Left = 240
TabIndex = 6
Top = 1200
Width = 2895
End
Begin VB.OptionButton optDlType
Caption = "下在到文本框"
Height = 255
Index = 2
Left = 240
TabIndex = 5
Top = 1440
Value = -1 'True
Width = 2895
End
End
Begin VB.Frame Frame3
Caption = "进度"
Height = 975
Left = 30
TabIndex = 1
Top = 2190
Width = 3255
Begin VB.PictureBox picProgress
AutoRedraw = -1 'True
ForeColor = &H8000000D&
Height = 255
Left = 120
ScaleHeight = 1
ScaleMode = 0 'User
ScaleWidth = 100
TabIndex = 2
Top = 600
Width = 3015
End
Begin VB.Label lblDownloadStatus
BackStyle = 0 'Transparent
Caption = "现在已经下载/总共大小"
Height = 255
Left = 120
TabIndex = 3
Top = 240
Width = 3015
End
End
Begin VB.CommandButton cmdFetch
Caption = "开始下载"
Height = 375
Left = 3900
TabIndex = 0
Top = 4200
Width = 2055
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "要下在的文件"
Height = 195
Left = 30
TabIndex = 26
Top = 120
Width = 1110
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' **********************************************************************
' 描 述:vb写的下在文件的类,没有用任何控件
' Play78.com : 网站导航,源码之家,绝对开源
' 海阔天空收集整理
' 主站地址:http://www.play78.com/
' 源码下载地址:http://www.play78.com/blog
' 图片下在地址:http://www.play78.com/pic
' 论坛地址:http://www.play78.com/bbs '欢迎大家加入讨论
' QQ:13355575
' e-mail:hglai@eyou.com
' 日期:2005年11月03日
' **********************************************************************
Dim WithEvents RemoteFile As DataConnection
Attribute RemoteFile.VB_VarHelpID = -1
Dim DlType As DOWNLOAD_TYPE
Private Sub Form_Load()
'Initialize WinSock... (this*must* be done)
StartWinsock vbNullString
'Create a new DataConnection class
Set RemoteFile = New DataConnection
'Set default proxy to 'No Proxy'
cmbProxyServer.ListIndex = 0
'Set default download type to Stream Buffer
optDlType_Click 2
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Clean up...
Set RemoteFile = Nothing
EndWinsock
End Sub
Private Sub optDlType_Click(Index As Integer)
optDlToFile(0).Enabled = (Index = 0)
optDlToFile(1).Enabled = (Index = 0)
txtFilename.Enabled = (Index = 0)
DlType = Index
End Sub
Private Sub cmbProxyServer_Click()
chkRemoteDNS.Enabled = (cmbProxyServer.ListIndex = 2 Or cmbProxyServer.ListIndex = 3)
txtPassword.Enabled = (cmbProxyServer.ListIndex = 3)
txtUsername.Enabled = chkRemoteDNS.Enabled
txtProxy.Enabled = (cmbProxyServer.ListIndex <> 0)
txtProxyPort.Enabled = (cmbProxyServer.ListIndex <> 0)
End Sub
Private Sub cmdFetch_Click()
txtOutput.Text = ""
With RemoteFile
.DownloadType = DlType
.Filename = txtFilename.Text
.UseTempFile = optDlToFile(1).Value
.ProxyType = cmbProxyServer.ListIndex
.ProxyHostname = txtProxy.Text
.ProxyPort = Val(txtProxyPort.Text)
.ProxyUsername = txtUsername.Text
.ProxyPassword = txtPassword.Text
.ProxyUseRemoteDNS = (chkRemoteDNS.Value = vbChecked)
.AutoRedirect = True
.AllowCache = False
.UseResume = False
picProgress.Cls
.Disconnect
.HttpUser = txtHttpUser.Text
.HttpPass = txtHttpPass.Text
.UseHttpAuthorization = True
.ResumeFrom = Val(txtResumeFrom.Text)
.UseResume = True
.PacketSize = 10000
.FetchURLString txtURL.Text
.MaxDownload = Val(txtMaxBytes)
End With
End Sub
Private Sub RemoteFile_BytesReceived(lByteCount As Long, ID As Long)
'If the script knows how many bytes that it has to receive then
If RemoteFile.DownloadLength > 0 Then
'... draw a progress bar
lblDownloadStatus.Caption = "已经下载 " + CStr(lByteCount) + " bytes 共 " + CStr(RemoteFile.DownloadLength) + "."
picProgress.ScaleWidth = RemoteFile.DownloadLength
picProgress.Line (0, 0)-(lByteCount, 1), , BF
'Or else, simply show how many bytes we have received
Else
lblDownloadStatus.Caption = "Downloaded " + CStr(lByteCount) + " bytes."
End If
End Sub
Private Sub RemoteFile_Connected(ID As Long)
'Successfully connected to the remote host
Debug.Print "Connected"
End Sub
Private Sub RemoteFile_Disconnected(ID As Long)
Debug.Print "Disconnected"
'If we have downloaded everything to a buffer...
If RemoteFile.DownloadType = dtToBuffer Then
'... then show it
txtOutput.Text = RemoteFile.GetBufferAsString
RemoteFile.ClearBuffer
End If
'Tell the user the download is complete
If RemoteFile.DownloadType = dtToFile And RemoteFile.UseTempFile Then
MsgBox "Download completed!" + vbCrLf + "Result saved to " + RemoteFile.Filename, vbInformation
Else
MsgBox "Download completed!", vbInformation
End If
End Sub
Private Sub RemoteFile_DownloadFailed(Why As DOWNLOAD_FAILURE, ID As Long)
'Uhoh... the download failed :(
Debug.Print "Download Failed"
MsgBox "The download failed... Error code " + CStr(Why), vbExclamation
MsgBox RemoteFile.HTTPReply
End Sub
Private Sub RemoteFile_ObjectMoved(sNewUrl As String, ID As Long)
Debug.Print "Object moved to " & sNewUrl
End Sub
Private Sub RemoteFile_StreamBytes(lByteCount As Long, bBytes() As Byte, ID As Long)
'Show the received bytes
txtOutput.Text = txtOutput.Text + StrConv(bBytes, vbUnicode)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -