自動出現動畫、進度和確認的文件操作
發表于:2007-07-14來源:作者:點擊數:
標簽:
使用以下的 API , 得到與資源管理器相同的感覺! 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 '只有在 F
使用以下的 API , 得到與資源管理器相同的感覺!
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 '只有在 FOF_SIMPLEPROGRESS 時用
End Type
Private Declare Function SHFileOperation Lib _
"shell32.dll" Alias "SHFileOperationA" (lpFileOp _
As SHFILEOPSTRUCT) As Long
'wFunc 常數
'FO_COPY 把 pFrom 文件拷貝到 pTo。
Const FO_COPY = &H2
'FO_DELETE 刪除 pFrom 中的文件(pTo 忽略)。
Const FO_DELETE = &H3
'FO_MOVE 把 pFrom 文件移動到 pTo。
Const FO_MOVE = &H1
'fFlag 常數
'FOF_ALLOWUNDO 允許 Undo 。
Const FOF_ALLOWUNDO = &H40
'FOF_NOCONFIRMATION 不顯示系統確認對話框。
Const FOF_NOCONFIRMATION = &H10
'FOF_NOCONFIRMMKDIR 不提示是否新建目錄。
Const FOF_NOCONFIRMMKDIR = &H200
'FOF_SILENT 不顯示進度對話框
Const FOF_SILENT = &H4
例子:
Dim SHFileOp As SHFILEOPSTRUCT
' 刪除
SHFileOp.wFunc = FO_DELETE
SHFileOp.pFrom = "c:\config.old" + Chr(0)
SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATION
Call SHFileOperation(SHFileOp)
' 刪除多個文件
SHFileOp.wFunc = FO_DELETE
SHFileOp.pFrom = "c:\config.old" +Chr(0) + "c:\autoexec.old"+Chr(0)
SHFileOp.fFlags = FOF_ALLOWUNDO
Call SHFileOperation(SHFileOp)
' 拷貝
SHFileOp.wFunc = FO_COPY
SHFileOp.pFrom = "c:\t\*.*"
SHFileOp.pTo = "d:\t\*.*"
SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMMKDIR
Call SHFileOperation(SHFileOp)
' 移動
SHFileOp.wFunc = FO_MOVE
SHFileOp.pFrom = "c:\config.old" + Chr(0)
SHFileOp.pTo = "d:\t"
SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATION
自動出現動畫、進度和確認的文件操作
==================================================================
使用以下的 API , 得到與資源管理器相同的感覺!
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 '只有在 FOF_SIMPLEPROGRESS 時用
End Type
Private Declare Function SHFileOperation Lib _
"shell32.dll" Alias "SHFileOperationA" (lpFileOp _
As SHFILEOPSTRUCT) As Long
'wFunc 常數
'FO_COPY 把 pFrom 文件拷貝到 pTo。
Const FO_COPY = &H2
'FO_DELETE 刪除 pFrom 中的文件(pTo 忽略)。
Const FO_DELETE = &H3
'FO_MOVE 把 pFrom 文件移動到 pTo。
Const FO_MOVE = &H1
'fFlag 常數
'FOF_ALLOWUNDO 允許 Undo 。
Const FOF_ALLOWUNDO = &H40
'FOF_NOCONFIRMATION 不顯示系統確認對話框。
Const FOF_NOCONFIRMATION = &H10
'FOF_NOCONFIRMMKDIR 不提示是否新建目錄。
Const FOF_NOCONFIRMMKDIR = &H200
'FOF_SILENT 不顯示進度對話框
Const FOF_SILENT = &H4
例子:
Dim SHFileOp As SHFILEOPSTRUCT
' 刪除
SHFileOp.wFunc = FO_DELETE
SHFileOp.pFrom = "c:\config.old" + Chr(0)
SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATION
Call SHFileOperation(SHFileOp)
' 刪除多個文件
SHFileOp.wFunc = FO_DELETE
SHFileOp.pFrom = "c:\config.old" +Chr(0) + "c:\autoexec.old"+Chr(0)
SHFileOp.fFlags = FOF_ALLOWUNDO
Call SHFileOperation(SHFileOp)
' 拷貝
SHFileOp.wFunc = FO_COPY
SHFileOp.pFrom = "c:\t\*.*"
SHFileOp.pTo = "d:\t\*.*"
SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMMKDIR
Call SHFileOperation(SHFileOp)
' 移動
SHFileOp.wFunc = FO_MOVE
SHFileOp.pFrom = "c:\config.old" + Chr(0)
SHFileOp.pTo = "d:\t"
SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATION
原文轉自:http://www.anti-gravitydesign.com