- 浏览: 174683 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
xiangyufangai:
很好很强大膜拜中哈哈!!
VB 两个字符串处理函数(类似Left/Mid/Right/Split的结合) -
hellohank:
这个……叫摘要算法,不叫加密算法~
Java实现的加密工具类(支持MD5和SHA) -
NIUCH1029291561:
接口有问题奥
网银在线支付接口和应用 -
yeuego:
能幫你就行了
MySQL索引分析 -
ForgiDaved:
很给力的介绍。记得前段时间给一个系统加功能,设计的表没有 ...
MySQL索引分析
'#############################
'**
'** 文件 frmDownLoad.frm 的内容
'**
'#############################
VERSION 5.00
Begin VB.Form frmDownLoad
BorderStyle = 1 'Fixed Single
Caption = "Form1"
ClientHeight = 2880
ClientLeft = 45
ClientTop = 330
ClientWidth = 6375
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "文件下载"
MaxButton = 0 'False
ScaleHeight = 2880
ScaleWidth = 6375
StartUpPosition = 2 'CenterScreen
Begin VB.CommandButton cmdStop
Caption = "停止"
Enabled = 0 'False
Height = 480
Left = 1860
TabIndex = 6
Top = 2160
Width = 1365
End
Begin VB.CommandButton cmdStart
Caption = "开始"
Height = 480
Left = 165
TabIndex = 5
Top = 2160
Width = 1365
End
Begin VB.TextBox txtFile
Height = 330
Left = 750
TabIndex = 3
Top = 705
Width = 5445
End
Begin VB.TextBox txtURL
Height = 330
Left = 750
TabIndex = 1
Top = 285
Width = 5445
End
Begin VB.Label lblCount
BackStyle = 0 'Transparent
Caption = "下载"
Height = 180
Left = 180
TabIndex = 4
Top = 1245
Width = 5130
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "文件:"
Height = 180
Left = 195
TabIndex = 2
Top = 780
Width = 450
End
Begin VB.Label lblURL
AutoSize = -1 'True
Caption = "URL:"
Height = 180
Left = 195
TabIndex = 0
Top = 360
Width = 360
End
End
Attribute VB_Name = "frmDownLoad"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function StrFormatByteSize Lib "shlwapi" Alias _
"StrFormatByteSizeA" (ByVal dw As Long, ByVal pszBuf As String, ByRef _
cchBuf As Long) As String
Private Declare Function InternetOpen Lib "wininet.dll" _
Alias "InternetOpenA" (ByVal sAgent As String, _
ByVal lAccessType As Long, ByVal sProxyName As String, _
ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetOpenUrl Lib "wininet.dll" _
Alias "InternetOpenUrlA" (ByVal hOpen As Long, _
ByVal surl As String, ByVal sHeaders As String, _
ByVal lLength As Long, ByVal lFlags As Long, _
ByVal lContext As Long) As Long
Private Declare Function HttpOpenRequest Lib "wininet.dll" _
Alias "HttpOpenRequestA" _
(ByVal hInternetSession As Long, _
ByVal lpszVerb As String, _
ByVal lpszObjectName As String, _
ByVal lpszVersion As String, _
ByVal lpszReferer As String, _
ByVal lpszAcceptTypes As Long, _
ByVal dwFlags As Long, _
ByVal dwContext As Long) As Long
Private Declare Function InternetConnect Lib "wininet.dll" _
Alias "InternetConnectA" _
(ByVal hInternetSession As Long, _
ByVal lpszServerName As String, _
ByVal nProxyPort As Integer, _
ByVal lpszUsername As String, _
ByVal lpszPassword As String, _
ByVal dwService As Long, _
ByVal dwFlags As Long, _
ByVal dwContext As Long) As Long
Private Declare Function HttpSendRequest Lib "wininet.dll" _
Alias "HttpSendRequestA" _
(ByVal hHttpRequest As Long, _
ByVal sHeaders As String, _
ByVal lHeadersLength As Long, _
ByVal sOptional As String, _
ByVal lOptionalLength As Long) As Boolean
Private Declare Function InternetReadFile Lib "wininet.dll" _
(ByVal hFile As Long, ByRef sBuffer As Byte, _
ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) _
As Integer
Private Declare Function InternetCloseHandle Lib "wininet.dll" _
(ByVal hInet As Long) As Integer
Private Declare Function GetLastError Lib "kernel32" () As Long
' Adds one or more HTTP request headers to the HTTP request handle.
'Public Declare Function HttpAddRequestHeaders Lib "wininet.dll" Alias "HttpAddRequestHeadersA" _
'(ByVal hHttpRequest As Long, ByVal sHeaders As String, ByVal lHeadersLength As Long, _
'ByVal lModifiers As Long) As Integer
Private bolStop As Boolean
' 然后,我们可以得到包含了一份详细说明的URL文本文件,它显示在下面的函数中:
Public Function DownloadFile(ByVal surl As String, ByVal strFile As String) As Long
Dim s As String
Dim hOpen As Long
Dim hOpenUrl As Long
Dim bDoLoop As Boolean
Dim bRet As Boolean
Dim intFH As Integer
Dim sReadBuffer() As Byte
Dim lNumberOfBytesRead As Long
Dim lCount As Long
Dim myCount As New clsCount
Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_OPEN_TYPE_PROXY = 3
Const scUserAgent = "VB OpenUrl"
Const INTERNET_FLAG_RELOAD = &H80000000
lblCount.Caption = "正在连接服务器..."
lblCount.Refresh
hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
hOpenUrl = InternetOpenUrl(hOpen, surl, vbNullString, 0, INTERNET_FLAG_RELOAD, 0)
lCount = 0
If hOpen <> 0 And hOpenUrl <> 0 Then
intFH = FreeFile
If Dir(strFile) <> "" Then
VBA.FileSystem.Kill strFile
End If
Open strFile For Binary As #intFH
myCount.Clear
Do While True
ReDim sReadBuffer(2048)
bRet = InternetReadFile(hOpenUrl, sReadBuffer(0), 2048, lNumberOfBytesRead)
If lNumberOfBytesRead > 0 And bRet = True Then
'if lnumberofbytesread<>2048 then
ReDim Preserve sReadBuffer(0 To lNumberOfBytesRead - 1)
Put #intFH, , sReadBuffer
'
' buf.AddRange sReadBuffer, 0, lNumberOfBytesRead - 1
lCount = lCount + lNumberOfBytesRead
myCount.Count lNumberOfBytesRead
lblCount.Caption = "已下载 " & VBStrFormatByteSize(lCount) & " [ " & VBStrFormatByteSize(myCount.Speed) & " /秒 ]"
lblCount.Refresh
Else
Exit Do
End If
bolStop = False
DoEvents
If bolStop = True Then
Exit Do
End If
Loop
Close #intFH
lblCount.Caption = "共下载 " & lCount & " 字节"
Else
lblCount.Caption = "打开URL错误"
End If
If hOpenUrl <> 0 Then InternetCloseHandle (hOpenUrl)
If hOpen <> 0 Then InternetCloseHandle (hOpen)
Set myCount = Nothing
DownloadFile = lCount
End Function
Private Sub cmdStart_Click()
txtURL.Enabled = False
txtFile.Enabled = False
cmdStart.Enabled = False
cmdStop.Enabled = True
DownloadFile txtURL.Text, txtFile.Text
cmdStop.Enabled = False
cmdStart.Enabled = True
txtFile.Enabled = True
txtURL.Enabled = True
End Sub
Private Sub cmdStop_Click()
bolStop = True
End Sub
Private Sub SetText(ByVal txt As TextBox)
txt.Text = GetSetting(App.Title, Me.Name, txt.Name)
End Sub
Private Sub SaveText(ByVal txt As TextBox)
SaveSetting App.Title, Me.Name, txt.Name, txt.Text
End Sub
Private Sub Form_Load()
SetText Me.txtFile
SetText Me.txtURL
End Sub
Private Sub Form_Unload(Cancel As Integer)
SaveText Me.txtFile
SaveText Me.txtURL
End Sub
Private Function VBStrFormatByteSize(ByVal lngSize As Long) As String
Dim strSize As String * 128
Dim strData As String
Dim lPos As Long
StrFormatByteSize lngSize, strSize, 128
lPos = InStr(1, strSize, Chr$(0))
strData = Left$(strSize, lPos - 1)
If lngSize > 1024 Then
strData = lngSize & "字节(" & strData & ")"
End If
VBStrFormatByteSize = strData
End Function
'########################
'**
'** 文件 clsCount.cls 的内容
'**
'########################
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsCount"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'******************************************************************************
'**
'** 用于计算速度的类模块
'**
'** 该类模块设定一个计数器,由程序不断的累计数据,并根据所花时间计算数据
'**
'** 编制: 袁永福
'** 时间: 2002-4-2
'**
'******************************************************************************
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private lngCountStart As Long
Private lngCountCurrent As Long
Private lngCountLast As Long
Private lngSpeed As Long
Private lngTickStart As Long
Private lngTickCurrent As Long
Private lngTickLast As Long
'Public StopCount As Boolean
'** 获得计数数据 **************************************************************
'** 累计初始值
Public Property Get CountStart() As Long
CountStart = lngCountStart
End Property
'** 累计终止值
Public Property Get CountEnd() As Long
CountEnd = lngCountCurrent
End Property
'** 累计总的速度
Public Property Get TotalSpeed() As Long
If lngTickCurrent = lngTickStart Then
TotalSpeed = 0
Else
TotalSpeed = (lngCountCurrent - lngCountStart) / ((lngTickCurrent - lngTickStart) / 1000)
End If
End Property
'** 累计所花毫秒数
Public Property Get TotalTickCount() As Long
TotalTickCount = lngTickCurrent - lngTickStart
End Property
'** 清除所有数据 **************************************************************
Public Sub Clear()
lngCountStart = 0
lngCountCurrent = 0
lngCountLast = 0
lngSpeed = 0
lngTickStart = GetTickCount()
lngTickCurrent = lngTickStart
lngTickLast = lngTickStart
'StopCount = False
End Sub
'** 设置累计基数
Public Property Let CountStart(ByVal lStart As Long)
lngCountStart = lStart
lngCountCurrent = lStart
End Property
'** 累加数据 **
Public Sub Count(Optional ByVal lCount As Long = 1)
lngCountCurrent = lngCountCurrent + lCount
lngTickCurrent = GetTickCount()
End Sub
'** 获得速度 **
Public Property Get Speed() As Long
'lngTickCurrent = GetTickCount()
If lngTickLast = lngTickCurrent Then
Speed = lngSpeed
Else
Speed = (lngCountCurrent - lngCountLast) / ((lngTickCurrent - lngTickLast) / 1000)
lngSpeed = Speed
lngTickLast = lngTickCurrent
lngCountLast = lngCountCurrent
End If
End Property
'** 数据是否是最新更新的 **
Public Property Get NewSpeed() As Boolean
Dim bolNew As Boolean
If lngTickCurrent > lngTickLast + 1000 Then
bolNew = True
Else
bolNew = False
End If
NewSpeed = bolNew
End Property
发表评论
-
vb 启动外部程序并且模拟鼠标点击
2011-03-09 13:28 1163Imports System.Runtime.InteropS ... -
VB 列出SQL数据库中所有表及字段信息
2011-03-09 13:24 1155程序思想:用Select name From sysobje ... -
VB 纯代码实现Timer控件的功能
2011-03-09 13:23 1356本博客有一篇类似的文章《VB 中运用 TimeSetEvent ... -
VB 控制音量
2011-03-09 13:22 1233'按钮一是音量增加,按钮二是音量减少,按钮三是静音切换. ... -
拦截 VB TextBox 双击消息
2011-03-09 13:22 949我们都知道在VB中TextBox默认是没有双击消息过程的(也就 ... -
VB 获取/设置屏幕分辨率
2011-03-09 13:21 1114Option ExplicitPrivate Decla ... -
VB 将数据快速导入EXCEL
2011-03-09 13:21 1036Public Function ToExcel()On ... -
VB 建立快捷方式
2011-03-09 13:20 783Private Declare Function fCr ... -
VB 获取快捷方式原文件路径
2011-03-09 13:20 924'此方法不需要引用IShellLink.Private ... -
VB 的一组字符串转换函数
2011-03-09 13:20 787Public Function chrConvert(s ... -
VB 在浏览目录时指定初始目录
2011-03-09 13:19 1061'VB也可以使用CallBack,下面是一个例子: '先 ... -
VB 获得鼠标滚轮的事件
2011-03-09 13:18 997'窗体代码Private Sub Form_Load() ... -
VB 比较两组字符串
2011-03-09 13:18 1290【方法一】 StrComp(string1, Stri ... -
VB 窗口处理技巧大全
2011-03-09 13:17 787VB提供了API函数SetWindowLong和GetWind ... -
VB 实现屏幕右下角浮出式消息窗口,透明淡出效果。
2011-03-09 13:16 991'任务栏高度[此部分相关代码转载自 枕善居]Privat ... -
VB Filter 函数用法
2011-03-09 13:16 1958例子1:Dim aa(10) As StringDim bbD ... -
VB 在EXPLORER进程崩溃之后重建托盘图标
2011-03-09 13:15 851重点为:向系统注册“TaskbarCreated”消息 ... -
Shell 调用程序后等待该程序结束后返回继续
2011-03-09 13:15 1226方法1: Private Declare Functi ... -
VB 最简单的WAV声音或音乐文件播放的代码
2011-03-09 13:14 1375'最简单的WAV声音或音乐文件播放的代码'API声明Pr ... -
VB 实现保存 Direct3D 游戏截图
2011-03-09 13:13 1505Written By Microsoft MVP: Eric ...
相关推荐
`URLDownloadToFile` API函数是Windows系统提供的一个强大工具,它允许VB应用程序直接从指定的URL下载文件到本地磁盘。这个API函数是Internet Explorer组件的一部分,包含在Wininet.dll库中。 `URLDownloadToFile`...
在VB(Visual Basic)编程中,`URLDownloadToFile`是一个非常实用的API函数,它允许开发者从指定的URL下载文件到本地系统。这个函数属于Windows操作系统内置的`Wininet.dll`库,它提供了网络访问的功能,包括HTTP、...
在"VB 纯API文件打开与保存对话框"的示例中,核心API函数可能包括`GetOpenFileName`和`GetSaveFileName`,这两个函数分别用于打开文件对话框和保存文件对话框。它们允许用户从文件系统中选择一个文件,或者指定一个...
`vbapi.chm`可能是一个包含VB API相关函数和方法的离线帮助文档,`.chm`是Microsoft的帮助文件格式,用于存储HTML和相关资源,便于用户查找和学习API的使用方法。 `VisualBasic手册.chm`很可能是Visual Basic的官方...
API的使用在VB6.0编程中至关重要,例如,如果需要进行文件操作,如创建、读取或删除文件,可以通过调用CreateFile、ReadFile和DeleteFile等API函数实现。又如,如果需要实现系统级别的交互,如控制鼠标和键盘,可以...
1. **Example102-复制文件(CopyFile)**: 这个示例展示了如何使用API函数`CopyFile`来复制一个文件到另一个位置。在VB中,通常使用`FileCopy`函数,但`CopyFile`提供了更多的选项,如覆盖已存在文件的能力。 2. **...
API实例则展示了如何在VB6.0程序中有效地使用这些API函数,帮助开发者理解和应用API来解决实际问题。 API实例.doc可能包含的内容有: 1. **文件操作**:如使用CreateFile、ReadFile、WriteFile等函数进行文件读写...
VBapi100个经典实例(功能齐全)这个资源涵盖了Visual Basic (VB)编程中使用API函数的各种实用示例。API(Application Programming Interface)是操作系统为开发者提供的接口,允许程序与操作系统进行交互,实现更...
通过这个工具,用户可以查找特定的API函数,查看其参数、返回值和使用示例,从而在VB代码中正确地调用这些函数。 而WIN32API.TXT 文件可能是一个文本文件,包含了Win32 API的详细信息,包括函数声明、参数说明以及...
"一百多个vb api详细实例 让你快速掌握常用api" 这个资源提供了丰富的VB API应用示例,帮助初学者和有经验的开发者更深入地理解如何利用API来增强VB程序的功能。 API在VB中的应用是多样的,涵盖了各种系统操作和...
在VB(Visual Basic)编程环境中,使用官方API来读写JSON数据格式文件是常见的操作,尤其是在处理网络数据交换或者存储配置信息时。JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,易于人阅读和...
这通常需要查阅API函数的文档,如VBAPI函数参考手册。 为了更好地掌握这项技能,建议初学者可以阅读专门介绍VB调用API的书籍,这些书籍通常会详细介绍如何声明、调用API函数,以及如何处理各种情况。此外,实践是...
VB.NET API浏览器是一款专为VB.NET开发者设计的实用工具,旨在简化API函数的查找和使用过程。这款浏览器能够自动生成适用于VB.NET环境的API函数,极大地提升了开发效率和代码的可读性。API(Application Programming...
在VB(Visual Basic)环境中,我们可以使用API(Application Programming Interface)来实现FTP的功能,如文件的上传和下载。API是操作系统提供的一组函数,允许开发者直接与操作系统交互,执行特定任务。在VB中,...
这个程序可能是从一本VB教程或实例集合中提取的,目的是为了让VB初学者了解如何使用API进行文件操作,尤其是文件搜索。代码中包含了详细的注释,以帮助学习者理解每一部分的功能和用法。 标签“VB源码-文件操作”...
VB API工具通过集成API函数库和示例代码,简化了开发过程,特别是对于那些需要频繁使用系统级功能的项目。 此工具特别强调其对.NET框架的支持,这意味着不仅传统的Visual Basic 6开发者可以受益,使用VB.NET的...
在“VBAPI函数参考手册.chm”这个帮助文件中,可能包含了各种API函数的详细说明,包括函数原型、参数解释、返回值、错误处理等方面的信息。这种手册对于开发者来说是非常宝贵的资源,可以帮助他们正确、安全地使用VB...
下面是一段使用API控制ListBox添加数据的示例代码: ```vb Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As ...
在"API大全"这个压缩包文件中,很可能包含了详细的API函数列表、参数说明、使用示例以及一些实用的VB 6.0 API函数库。这样的资源对于学习和使用VB 6.0 API开发是非常宝贵的,可以帮助开发者快速查找和应用API函数,...
在这个“VB如何拦截API调用.apihook钩子”的项目中,我们可以看到一系列的VB文件,它们共同实现了一个API Hook的示例。 1. **Module1.bas** 和 **Module2.bas**: 这两个模块可能包含了VB代码,用于实现API Hook的...