Friday, June 8, 2012

Animasi Copy Seperti Di Windows Explorer

Option Explicit 

Private Const
FO_COPY = &H2&
Private Const FO_DELETE = &H3&
Private Const FO_MOVE = &H1&
Private Const FO_RENAME = &H4&
Private Const FOF_ALLOWUNDO = &H40&
Private Const FOF_CONFIRMMOUSE = &H2&
Private Const FOF_CREATEPROGRESSDLG = &H0&
Private Const FOF_FILESONLY = &H80&
Private Const FOF_MULTIDESTFILES = &H1&
Private Const FOF_NOCONFIRMATION = &H10&
Private Const FOF_NOCONFIRMMKDIR = &H200&
Private Const FOF_RENAMEONCOLLISION = &H8&
Private Const FOF_SILENT = &H4&
Private Const FOF_SIMPLEPROGRESS = &H100&
Private Const FOF_WANTMAPPINGHANDLE = &H20&

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 String
End Type

Private Declare Sub
CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Function SHFileOperation Lib "Shell32.dll" Alias "SHFileOperationA" (lpFileOp As Any) As Long

Private Sub
cmdCopy_Click()
Dim result As Long
Dim
lenFileop As Long
Dim
foBuf() As Byte
Dim
fileop As SHFILEOPSTRUCT

lenFileop = LenB(fileop)
ReDim foBuf(1 To lenFileop)

With
fileop
.hwnd = Me.hwnd
.wFunc = FO_COPY
.pFrom = App.Path & "\readme.html" & vbNullChar & App.Path & "\readme.doc" & vbNullChar & App.Path & "\readme.txt" & vbNullChar & vbNullChar
.pTo = "C:\"
.fFlags = FOF_CREATEPROGRESSDLG
.lpszProgressTitle = "VB HowTo Copy Example " & vbNullChar & vbNullChar
End With

Call
CopyMemory(foBuf(1), fileop, lenFileop)
Call CopyMemory(foBuf(19), foBuf(21), 12)

result = SHFileOperation(foBuf(1))

If
result <> 0 Then
MsgBox Err.LastDllError
Else
If
fileop.fAnyOperationsAborted <> 0 Then
MsgBox "Operation Failed"
End If
End If

End Sub