I used to use the API function that can only call the replication of the system to display the progress. There are other methods to use, but this API can only be on the NT4.0 and above. Adding a module in the project, copy the following code to the module in Private Const PROGRESS_CANCEL = 1Private Const PROGRESS_CONTINUE = 0Private Const PROGRESS_QUIET = 3Private Const PROGRESS_STOP = 2Private Const COPY_FILE_FAIL_IF_EXISTS = & H1Private Const COPY_FILE_RESTARTABLE = & H2
'// This API can not be used Private Declare Function CopyFileEx Lib "kernel32.dll" Alias "CopyFileExA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal lpProgressRoutine As Long, lpData As Any, ByRef pbCancel As Long at WIN9X, ByVal DWCopyFlags as long) As long
Private mlngcancel as longprivate mprgState as ObjectPrivate Mlblstate As Object
Public Function CopyProgressRoutine (ByVal TotalFileSize As Currency, _ ByVal TotalBytesTransferred As Currency, _ ByVal StreamSize As Currency, _ ByVal StreamBytesTransferred As Currency, _ ByVal dwStreamNumber As Long, _ ByVal dwCallbackReason As Long, _ ByVal hSourceFile As Long, _ ByVal hDestinationFile As Long _ Byval lpdata as long) As long '// Display progress mPrgState.Value = ClNG ((100 / TotalFileSize) MLBLSTATE.CAPTION = "Completed:" & formatpers) '// Continue copy CopyProgressRoutine = Progress_ContinueEnd Function
'********************************************** ** function name: ucopyfile '** function function: copy file' ** parameter description: '** strfrom source file' ** STRTO target file '** prgState progress bar control' ** lblstate used to display the progress of label ' ** Function Returns: '** Boolean Type' ** True Copy Success '** False Copy Failed' ** Reference Instance: '**' ** Blnreturn = UcopyFile ("c: /test.exe", "D: / Test.exe ", prgState, lblstate) '************************************************* ********* Public Function uCopyFile (ByVal strFrom As String, _ ByVal strTo As String, _ ByRef prgState As Object, _ ByRef lblState As Object) As Boolean Dim lngReturn As Long Set mprgState = prgState Set mlblState = lblState '// Start copying lngreturn = copyfileex (strfrom, strogressroutine, byval 0 &, mlngcancel, copy_file_restartable) if LNG Return = 0 THEN UCOPYFILE = false else ucopyfile = true end ifend function When you call, use ucopyfile ("c: /test.exe", "d: /test.exe", prgState, lblstate, where you can Don't go, by yourself.