在標准工程中添加一個公共對話框和兩個按鈕即可嘗試本例:
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->