【 tulaoshi.com - 编程语言 】
在标准工程中添加一个公共对话框和两个按钮即可尝试本例:
OptionExplicit
'删除文件的API
PrivateDeclareFunctionSHFileOperationLib"shell32.dll"Alias"SHFileOperationA"(lpFileOpAsToBin)AsLong
'清空回收站的API
PrivateDeclareFunctionSHEmptyRecycleBinLib"shell32.dll"Alias"SHEmptyRecycleBinA"(ByValhwndAsLong,ByValpszRootPathAsString,ByValdwFlagsAsLong)AsLong
PrivateTypeToBin
hwndAsLong
wFuncAsLong
pFromAsString
pToAsString
fFlagsAsInteger
fAnyOperationsAbortedAsLong
hNameMappingsAsLong
lpszProgressTitleAsLong
EndType
ConstFO_DELETE=&H3
ConstFOF_ALLOWUNDO=&H40
ConstSHERB_NORMAL=&H0
'将文件移至回收站
PrivateSubCommand1_Click()
DimGoAsToBin
DimstrFileAsString
WithCommonDialog1
.Filter="(*.bak)|*.bak"
.DialogTitle="删除文件"
.ShowOpen
strFile=.FileName
EndWith
WithGo
.wFunc=FO_DELETE
.pFrom=strFile
.fFlags=FOF_ALLOWUNDO
EndWith
SHFileOperationGo
EndSub
'清空回收站
PrivateSubCommand2_Click()
DimRetValAsLong
RetVal=SHEmptyRecycleBin(0&,vbNullString,SHERB_NORMAL)
EndSub->