如何在文件拷贝中使用进度条
编号:QA001742
建立日期: 1999年9月22日 最后修改日期:1999年9月27日
所属类别:
陈鸿伟:
VB5
win98
如何在文件拷贝中使用进度条?VB的FileCopy函数无法知道拷贝了多少字节,进度条的Value无法知道。
回答:
FileCopy的确存在你说的问题。你可以使用API函数SHFileOperation,这个函数可以实现拷贝功能,同时还可以显示带有进度条的标准动画对话框。该函数的使用可以参考微软的Knowledge Base的文章:“Q151799 OWTO: Use the Animated Copy Functions in Windows 95/98”。
陈鸿伟来信表示:对SHFileOperation还不太满意,因为它要打开自己的窗口,我希望的是把进度条嵌入到我的窗口中。他提出下面的解决办法:
Public sub CopyFile(Src As String, Dst As String) As Single
Dim BTest!, FSize!
Dim F1%, F2%
Dim sArray() As Byte
Dim buff As Integer
Const BUFSIZE = 1024
buff = 1024
F1 = FreeFile
Open Src For Binary As F1
F2 = FreeFile
Open Dst For Binary As F2
FSize = LOF(F1)
BTest = FSize - LOF(F2)
ReDim sArray(BUFSIZE) As Byte
Do
If BTest < BUFSIZE Then
buff = BTest
ReDim sArray(buff) As Byte
End If
Get F1, , sArray
Put F2, , sArray
BTest = FSize - LOF(F2)
If BTest < 0 Then
ProgressBar.Value = 100
Else
ProgressBar.Value = (100 - Int(100 * BTest / FSize))
End If
Loop Until BTest <= 0
Close F1
Close F2
CopyFile = FSize
End sub
此问题由李海回答。
| |
|
|
| |
|
|