首页 > 学院 > 开发设计 > 正文

如何使用文件复制对话框

2019-11-18 17:40:10
字体:
来源:转载
供稿:网友
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->


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表