为窗体FORM1的命令按钮"执行"的click事件写代码,实现下述功能:
调用SHFileOperation,将文件列表框中选择的文件删除到回收站.

解决方案 »

  1.   

    窗口中添加控件DrviceListBox,CommondButton,DirListBox,FileListBox
    示例代码如下:
    Option ExplicitPrivate Sub Command1_Click()
        Dim SHFileOp As SHFILEOPSTRUCT
        Dim Path As String, pFrom As String, i As Integer    Path = File1.Path
        If Right(Path, 1) <> "\" Then Path = Path & "\"
        For i = 0 To File1.ListCount - 1
            If File1.Selected(i) Then
                pFrom = pFrom & Path & File1.List(i) & Chr(0)
            End If
        Next
        
        SHFileOp.wFunc = FO_DELETE
        SHFileOp.pFrom = pFrom
        SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATION
        SHFileOperation SHFileOp    File1.Refresh
    End SubPrivate Sub Dir1_Change()
        File1.Path = Dir1.Path
    End SubPrivate Sub Drive1_Change()
        Dir1.Path = Drive1.Drive
    End Sub
      

  2.   

    模块中的声明:
    Option ExplicitPublic Const FO_MOVE = &H1
    Public Const FO_COPY = &H2
    Public Const FO_DELETE = &H3
    Public Const FO_RENAME = &H4Public Const FOF_NOCONFIRMATION = &H10
    Public Const FOF_NOCONFIRMMKDIR = &H200
    Public Const FOF_ALLOWUNDO = &H40Type SHFILEOPSTRUCT
        hWnd As Long
        wFunc As Long
        pFrom As String
        pTo As String
        fFlags As Integer
        fAborted As Boolean
        hNameMaps As Long
        sProgress As String
    End Type
    Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long