• SHFileOperationA 用法


    看到有人复制文件带进度条,搜了一下发现SHFileOperationA很简单就实现了

    Public Class Form1

    Private Declare Function SHFileOperation Lib "Shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
    Structure SHFILEOPSTRUCT
    Dim hwnd As IntPtr '窗口句柄
    Dim wFunc As Integer '执行的操作
    Dim pFrom As String '原地点
    Dim pTo As String '目标地点
    Dim fFlags As Int32 '操作执行方式
    Dim fAnyOperationsAborted As Integer '错误代码返回
    Dim hNameMappings As Integer
    Dim lpszProgressTitle As Integer 'String
    End Structure
    Private Const FO_MOVE As Integer = &H1
    Private Const FO_COPY As Integer = &H2
    Private Const FO_DELETE As Integer = &H3
    Private Const FOF_ALLOWUNDO As Integer = &H40

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim FileOp As New SHFILEOPSTRUCT
    Dim result As Integer
    Try
    With FileOp
    .hwnd
    = Me.Handle

    .wFunc
    = FO_COPY
    .pFrom
    = "F:\path\*.*" & Chr(0) & Chr(0) 'vbNullChar & vbNullChar
    .pTo = "c:\test" & Chr(0) & Chr(0) 'vbNullChar & vbNullChar

    .fFlags
    = FOF_ALLOWUNDO
    End With
    result
    = SHFileOperation(FileOp)
    If result <> 0 Then ' Operation failed
    If Err.LastDllError <> 0 Then
    MsgBox(Err.LastDllError) ' Msgbox the error that occurred in the API.
    End If
    Else
    If FileOp.fAnyOperationsAborted <> 0 Then
    MsgBox("Operation Failed")
    End If
    End If
    Catch ex As Exception
    MsgBox(ex.ToString)
    End Try


    End Sub
    End Class
  • 相关阅读:
    python中类方法、类实例方法、静态方法的使用与区别
    在python里如何动态添加类的动态属性呢?
    PYTHON基础
    EXCEL 写入
    thread 多线程
    Python 常用函数
    列表减列表
    04_Linux搭建Jdk和tomcat环境
    自动生成和安装requirements.txt依赖
    python+selenium面试题
  • 原文地址:https://www.cnblogs.com/LCX/p/2061447.html
Copyright © 2020-2023  润新知