VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Nitin G Parmar"
   ClientHeight    =   4860
   ClientLeft      =   3900
   ClientTop       =   2355
   ClientWidth     =   3165
   LinkTopic       =   "Form1"
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   4860
   ScaleWidth      =   3165
   Begin VB.FileListBox File1 
      Height          =   1845
      Left            =   360
      TabIndex        =   3
      Top             =   1920
      Width           =   2415
   End
   Begin VB.DirListBox Dir1 
      Height          =   1380
      Left            =   360
      TabIndex        =   2
      Top             =   480
      Width           =   2415
   End
   Begin VB.DriveListBox Drive1 
      Height          =   315
      Left            =   360
      TabIndex        =   1
      Top             =   120
      Width           =   2415
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Select A File"
      Default         =   -1  'True
      Height          =   495
      Left            =   480
      TabIndex        =   0
      Top             =   4080
      Width           =   2175
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Type SHFILEOPSTRUCT
     hwnd As Long
     wFunc As Long
     pFrom As String
     pTo As String
     fFlags As Integer
     fAnyOperationsAborted As Boolean
     hNameMappings As Long
     lpszProgressTitle As String
End Type
'API To send file to recycle bin
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Const FO_DELETE = &H3
Private Const FOF_ALLOWUNDO = &H40
Private Sub Command1_Click()
Dim FileOperation As SHFILEOPSTRUCT
Dim lReturn As Long
If File1.ListIndex = -1 Then
    MsgBox "Select A File To Send To Recycle bin"
    File1.SetFocus
    Exit Sub
End If
With FileOperation
    .wFunc = FO_DELETE
    .pFrom = File1.Path & "\" & File1.List(File1.ListIndex)     'fichier s閘ectionn?dans la liste
    .fFlags = FOF_ALLOWUNDO
End With
lReturn = SHFileOperation(FileOperation)
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End SubPrivate Sub Form_Load()
'Name:Nitin G Parmar
'Begineer in Vb
'Email:[email protected]
End Sub

解决方案 »

  1.   

    shfileoperation  API函數
    shfileopstruct 成員fflags指定fof_allowundo+fof_noconfirmation
    王國榮先生之<<Windows API講座>>有很多相關實例.
    要源碼聯系我:[email protected]
      

  2.   

    Private Type SHFILEOPSTRUCT
        hwnd As Long
        wFunc As Long
        pFrom As String
        pTo As String
        fFlags As Integer
        fAnyOperationsAborted As Long
        hNameMappings As Long
        lpszProgressTitle As Long
    End TypePrivate Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As LongPrivate Const FO_DELETE = &H3
    Private Const FOF_ALLOWUNDO = &H40
    Private Sub Form_Load()
    Dim SHop As SHFILEOPSTRUCT
    Dim strFile As String
    strFile = "文件路径"
    With SHop
        .wFunc = FO_DELETE
        .pFrom = strFile + Chr(0)
        .fFlags = FOF_ALLOWUNDO
    End With
    SHFileOperation SHopEnd Sub