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->