VisualBasic提供了过时的FileCopy语句.问题是使用该函数时并不显示文件复制对话框,也就是说,当拷贝一个大文件时,用户看不到Windows的标准
文件复制对话框,无法从进度条上判断当前复制的进度.那么,如何做到这一点呢?请看下面:
PublicTypeSHFILEOPSTRUCT
hWndAsLong
wFuncAsLong
pFromAsString
pToAsString
fFlagsAsInteger
fAnyOperationsAbortedAsBoolean
hNameMappingsAsLong
lpszProgressTitleAsString
EndType
PublicDeclareFunctionSHFileOperationLib"shell32.dll"Alias
_
"SHFileOperationA"(lpFileOpAsSHFILEOPSTRUCT)AsLong
PublicConstFO_COPY=&H2
PublicConstFOF_ALLOWUNDO=&H40
PublicSubShellCopyFile(SourceAsString,DestAsString)
DimresultAsLong
DimfileopAsSHFILEOPSTRUCT
Withfileop
.hwnd=0
.wFunc=FO_COPY
'ThefilestocopyseparatedbyNullsandterminatedby2nulls
.pFrom=Source&vbNullChar&vbNullChar
'ortocopyallfilesusethisline
'.pFrom="C:\*.*"&vbNullChar&vbNullChar
'Thedirectoryorfilename(s)tocopyintoterminatedin2nulls
.pTo=Dest&vbNullChar&vbNullChar
.fFlags=FOF_ALLOWUNDO
EndWith
result=SHFileOperation(fileop)
Ifresult<>0Then'Operationfailed
'MsgboxtheerrorthatoccurredintheAPI.
MsgBoxErr.LastDllError,vbCriticalOrvbOKOnly
Else
Iffileop.fAnyOperationsAborted<>0Then
MsgBox"OperationFailed",vbCriticalOrvbOKOnly
EndIf
EndIf
EndSub
只需调用ShellCopyFileFileA,FileACopy->