Option ExplicitPrivate 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 String ' only used if FOF_SIMPLEPROGRESS End TypePrivate Const FO_DELETE As Long = &H3 Private Declare Function GetDesktopWindow Lib "user32" () As Long Private Declare Function SHFileOperation Lib "Shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As LongPrivate Sub Command1_Click() Dim fileop As SHFILEOPSTRUCT Dim sfile As String Dim params As String Dim hWndDesk As Long, result As Long
With fileop params = vbNullString hWndDesk = GetDesktopWindow()
If result <> 0 Then MsgBox "对不起,操作失败!", vbExclamation Else If fileop.fAnyOperationsAborted <> 0 Then MsgBox "对不起,操作失败!", vbExclamation End If End If DoEvents End WithEnd Sub
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS
End TypePrivate Const FO_DELETE As Long = &H3
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function SHFileOperation Lib "Shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As LongPrivate Sub Command1_Click()
Dim fileop As SHFILEOPSTRUCT
Dim sfile As String
Dim params As String
Dim hWndDesk As Long, result As Long
With fileop
params = vbNullString
hWndDesk = GetDesktopWindow()
sfile = "d:\aa" '要删除的文件或文件
.hwnd = Me.hwnd
.wFunc = FO_DELETE
.pFrom = sfile & vbNullChar & vbNullChar
result = SHFileOperation(fileop)
If result <> 0 Then
MsgBox "对不起,操作失败!", vbExclamation
Else
If fileop.fAnyOperationsAborted <> 0 Then
MsgBox "对不起,操作失败!", vbExclamation
End If
End If
DoEvents
End WithEnd Sub