Using Explorer's File Copy Dialog Box
Ever wanted to use the dialog box that appears when you do file operations in Explorer? Well, it is not that hard to work, and can be used to provide some very neat little features for your application. One little warning before we go too much further: you can easily use this function to delete entire directories without any confirmation; I recommend that you create some temporary directories that you can play about with, rather than destroying any useful directories.
All the dialog boxes are based around one function, SHFileOperation. It is very easy to use, and only has one parameter, a SHFILEOPSTRUCT user-defined type. Here are the declarations that you will need:
Public Declare Function SHFileOperation Lib _ "shell32.dll" Alias "SHFileOperationA" _ (lpFileOp As Any) As LongPublic Declare Sub _ SHFreeNameMappings Lib _ "shell32.dll" (ByVal hNameMappings As Long) Public Declare Sub CopyMemory Lib "KERNEL32" _ Alias "RtlMoveMemory" (hpvDest As Any, hpvSource _ As Any, ByVal cbCopy As Long)Public Type SHFILEOPSTRUCT hwnd As Long wFunc As FO_Functions pFrom As String pTo As String fFlags As FOF_Flags fAnyOperationsAborted As Long hNameMappings As Long lpszProgressTitle As String 'only used if FOF_SIMPLEPROGRESS End Type Public Enum FO_Functions FO_MOVE = &H1 FO_COPY = &H2 FO_DELETE = &H3 FO_RENAME = &H4 End Enum Public Enum FOF_Flags FOF_MULTIDESTFILES = &H1 FOF_CONFIRMMOUSE = &H2 FOF_SILENT = &H4 FOF_RENAMEONCOLLISION = &H8 FOF_NOCONFIRMATION = &H10 FOF_WANTMAPPINGHANDLE = &H20 FOF_ALLOWUNDO = &H40 FOF_FILESONLY = &H80 FOF_SIMPLEPROGRESS = &H100 FOF_NOCONFIRMMKDIR = &H200 FOF_NOERRORUI = &H400 FOF_NOCOPYSECURITYATTRIBS = &H800 FOF_NORECURSION = &H1000 FOF_NO_CONNECTED_ELEMENTS = &H2000 FOF_WANTNUKEWARNING = &H4000 End Enum Public Type SHNAMEMAPPING pszOldPath As String pszNewPath As String cchOldPath As Long cchNewPath As Long End Type
Page 1 of 3
This article was originally published on November 20, 2002