带Windows进度条的复制函数-易勋
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> Access数据库-模块/函数/VBA


带Windows进度条的复制函数

发表时间:2019/3/7 10:34:29 评论(2) 浏览(4668)  评论 | 加入收藏 | 复制
   
摘 要:通过APICopyFile这个函数,复制文件或者文件夹,可以显示Windows的执行进度条。
正 文:

函数:

#If VBA7 Then
    Private Type API_SHFILEOPSTRUCT
        hwnd                        As LongPtr
        Func                        As LongPtr
        From                        As String
        To                          As String
        Flags                       As Integer
        AnyOperationsAborted        As Long
        NameMappings                As Long
        ProgressTitle               As String
    End Type
    Private Declare PtrSafe Function ApiSHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As API_SHFILEOPSTRUCT) As Long
#Else
    Private Type API_SHFILEOPSTRUCT
        hwnd                        As Long
        Func                        As Long
        From                        As String
        To                          As String
        Flags                       As Integer
        AnyOperationsAborted        As Long
        NameMappings                As Long
        ProgressTitle               As String
    End Type
    Private Declare Function ApiSHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As API_SHFILEOPSTRUCT) As Long
#End If

Public Function APICopyFile( _
        Pathname As String, _
        Optional Destination As String _
    ) As Boolean
    On Error Resume Next

    Dim typPath As API_SHFILEOPSTRUCT

    Const FOF_NOCONFIRMATION = &H10
    Const FOF_SILENT = &H4
    Const FOF_NOERRORUI = &H400

    typPath.hwnd = 0
    typPath.Func = 2

    If Right(Pathname, 1) <> "\" Then
        typPath.From = Pathname & "\*"
    Else
        typPath.From = Pathname & "*"
    End If

    If Right(Destination, 1) <> "\" Then
        typPath.To = Destination & "\"
    End If

    typPath.To = Destination

    APICopyFile = Not CBool(ApiSHFileOperation(typPath))
End Function


调用:

APICopyFile 当前路径, 目标路径

Access软件网交流QQ群(群号:198465573)
 
 相关文章
sqlserver 时间格式函数详解  【缪炜  2019/1/18】
打印报表的函数  【张志  2019/2/6】
【Access进度条】平台进度条函数的使用  【张迪  2019/2/11】
【Access基础】随机数函数--Rnd函数  【张迪  2019/2/18】
【Access源码】判断是否扫码枪输入的通用函数源码分享  【红尘如烟  2019/2/28】
常见问答
技术分类
相关资源
文章搜索
关于作者

易勋

文章分类

文章存档

友情链接