Sunday, May 27, 2012

Memindahkan File Ke Recycle Bin

Di bawah ini merupakan procedure untuk memindahkan/menghapus file ke dalam recycle bin. Bagaimana kodenya dalam Visual Basic 6.0? bisa kita simak di bawah ini:
Option Explicit 

Private Declare Function
SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Private 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 Long
End Type

Private Const
FO_DELETE = &H3
Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_NOCONFIRMATION = &H10
Private Const FOF_SILENT = &H4

Public Sub
SendFileToRecycleBin(FileName As String, Optional Confirm As Boolean = True, Optional Silent As Boolean = False)
Dim FileOp As SHFILEOPSTRUCT

With
FileOp
.wFunc = FO_DELETE
.pFrom = FileName
.fFlags = FOF_ALLOWUNDO
If Not Confirm Then .fFlags = .fFlags + FOF_NOCONFIRMATION
If Silent Then .fFlags = .fFlags + FOF_SILENT
End With
SHFileOperation FileOp
End Sub
Contoh penggunaan procedure di atas
Private Sub Command1_Click() 
SendFileToRecycleBin "c:\42.tmp", True, False
End Sub

READ MORE - Memindahkan File Ke Recycle Bin

Menghapus Seluruh File Yang Ada Dalam Recycle Bin

Di bawah ini merupakan fungsi untuk menghapus seluruh file yang terdapat pada recycle bin. Bagaimana implementasinya dalam Visual Basic 6.0? bisa Anda simak kodenya di bawah ini
Option Explicit 

Private Declare Function
SHEmptyRecycleBin Lib "shell32.dll" Alias "SHEmptyRecycleBinA" (ByVal hWnd As Long, ByVal pszRootPath As String, ByVal dwFlags As Long) As Long
Const
SHERB_NOCONFIRMATION = &H1
Const SHERB_NOPROGRESSUI = &H2
Const SHERB_NOSOUND = &H4

Public Sub
EmptyRecycleBin(frm As Form)
Dim RetVal
RetVal = SHEmptyRecycleBin(frm.hWnd, "", SHERB_NOPROGRESSUI + SHERB_NOCONFIRMATION)
End Sub
Contoh pengunaan procedure di atas
Private Sub Command1_Click() 
EmptyRecycleBin Me
End Sub

READ MORE - Menghapus Seluruh File Yang Ada Dalam Recycle Bin

Menghapus Seluruh File Recent Document

Di bawah ini merupakan procedure untuk menghapus seluruh yang terdapat pada recent document. Untuk keperluan ini digunakan satu fungsi API yakni SHAddToRecentDocs yang terdapat pada shell32.dll.
Option Explicit 

Private Declare Sub
SHAddToRecentDocs Lib "shell32.dll" (ByVal uFlags As Long, ByVal pv As Any)

Sub
EmptyRecentDocument()
SHAddToRecentDocs 0, CLng(0)
End Sub
Contoh penggunaan procedure di atas
Private Sub Command1_Click() 
EmptyRecentDocument
End Sub
READ MORE - Menghapus Seluruh File Recent Document

Fungsi Untuk Memeriksa Apakah Recycle Bin Kosong?

Di bawah ini merupakan fungsi untuk memeriksa apakah recycle bin kosong? Bagaimana implementasinya dalam Visual Basic 6.0? bisa Anda simak kodenya dibawah ini:
Option Explicit 

Private Type
SHQUERYRBINFO
cbSize As Long
i64SizeLo As Long
i64SizeHi As Long
i64NumItemsLo As Long
i64NumItemsHi As Long
End Type

Private Declare Function
SHQueryRecycleBin Lib "shell32" Alias "SHQueryRecycleBinA" (ByVal pszRootPath As String, pSHQueryRBInfo As SHQUERYRBINFO) As Long

Function
IsEmptyRecycle() As Boolean
Dim
RB As SHQUERYRBINFO
RB.cbSize = Len(RB)
Call SHQueryRecycleBin("C:\", RB)
IsEmptyRecycle = (RB.i64NumItemsLo = 0)
End Function
Contoh penggunaan fungsi di atas
Private Sub Command1_Click() 
MsgBox IsEmptyRecycle
End Sub
READ MORE - Fungsi Untuk Memeriksa Apakah Recycle Bin Kosong?