computer 版 (精华区)
发信人: windoe (为中国电信做贡献), 信区: program
标 题: VB:在Windows 95的资源管理器里删除文件时,文件都会
发信站: 听涛站 (Fri Mar 10 19:09:18 2000), 转信
现这种功能?
我们利用Windows API函数SHFileOperation来解决这个问题。实现步骤如下:
1) 在VB中新建一个标准EXE工程,添加模块Module1;
2) 在模块Module1中定义Windows API的声明和书写函数如下:
Public Const FO_DELETE = &H3
Public Const FOF_ALLOWUNDO = &H40
Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type
Declare Function SHFileOperation Lib "shell32.dll" Alias
"SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
'删除文件,放进垃圾回收站的函数
Public Function ShellDelete(ParamArray vntFileName() As Variant)
Dim I As Integer
Dim sFileNames As String
Dim SHFileOp As SHFILEOPSTRUCT
For I = LBound(vntFileName) To UBound(vntFileName)
sFileNames = sFileNames & vntFileName(I) & vbNullChar
Next I
sFileNames = sFileNames & vbNullChar
With SHFileOp
.wFunc = FO_DELETE
.pFrom = sFileNames
.fFlags = FOF_ALLOWUNDO
End With
ShellDelete = SHFileOperation(SHFileOp)
End Function
3) 在窗体Form1中画出按钮Command1;
4) 在Command1的Click事件中编写以下代码:
Private Sub Command1_Click()
Open "c:\test.txt" For Output As 1 '自动创建文件Test.txt
Print #1, "这是测试文件"
Close #1
ShellDelete "c:\test.txt" '删除文件,放进垃圾回收站
End Sub
--By Kammi's SuperPost General Version
--
夜中不能寐,起坐弹鸣琴。
薄帷鉴明月,清风吹我襟。
孤鸿号外野,翔鸟鸣北林。
徘徊将何见,忧思独伤心。
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:0.897毫秒