Option Explicit
'删除文件的API
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As ToBin) As Long
'清空回收站的API
Private Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias "SHEmptyRecycleBinA" (ByVal hwnd As Long, ByVal pszRootPath As String, ByVal dwFlags As Long) As Long
Private Type ToBin
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 Type
Const FO_DELETE = &H3
Const FOF_ALLOWUNDO = &H40
Const SHERB_NORMAL = &H0
'将文件移至回收站
Private Sub Command1_Click()
Dim Go As ToBin
Dim strFile As String
With CommonDialog1
.Filter = "(*.bak)|*.bak"
.DialogTitle = "删除文件"
.ShowOpen
strFile = .FileName
End With
With Go
.wFunc = FO_DELETE
.pFrom = strFile
.fFlags = FOF_ALLOWUNDO
End With
SHFileOperation Go
End Sub
'清空回收站
Private Sub Command2_Click()
Dim RetVal As Long
RetVal = SHEmptyRecycleBin(0&, VBNullString, SHERB_NORMAL)
End Sub
上一篇: VB数组小技巧一则
下一篇: 人民币金额转换例程
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




