zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    求最长不降子序列

    普通背包问题
    求最大子序列
    最大人品
    C# 显示webBrowser页面加载进度
    Provider 错误 '80004005' 未指定的错误 的最终解决方法
    C# 截取webBrowser网页存为图片
    浅谈Python小数据池
    js文件编译成动态链接库(dll)文件
  • 原文地址:https://www.cnblogs.com/LCX/p/2061447.html
Copyright © 2011-2022 走看看