敬业的IT人 >> 编程开发 >> VB >> 如何使用文件复制对话框

如何使用文件复制对话框

敬业的IT人 互联网 佚名 2008-1-3 17:21:27
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->

粤ICP备06119539号
Copyright CiscoSky.Org,Some Rights Reserved.
Email:me1228#tom.com