VB displays the file copy progress in the specified progress bar and tag.

Source: Internet
Author: User
Private   Const Progress_cancel =   1
Private   Const Progress_continue =   0
Private   Const Progress_quiet =   3
Private   Const Progress_stop =   2
Private   Const Copy_file_fail_if_exists =   & H1
Private   Const Copy_file_restartable =   & H2

' // This API cannot be used in Win9x
Private   Declare   Function copyfileex () 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 , Byval Dwcopyflags As   Long ) As   Long

Private Mlngcancel As   Long
Private Mprgstate As   Object
Private Mlblstate As   Object

Public   Function copyprogressroutine () 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) * Totalbytestransferred)
Mlblstate. Caption
=   " Completed: "   &   Formatpercent (Mprgstate. Value /   100 , 0 )
'
Doevents
' // Continue copying
Copyprogressroutine = Progress_continue
End Function


' **************************************** ********
'
** Function name: ucopyfile
'
** Function: copy an object
'
** Parameter description:
'
** Strfrom source file
'
** Strto target file
'
** Prgstate progress bar Control
'
** Lblstate: the label used to display the progress
'
** Function return:
'
** Boolean Type
'
** True: Copied successfully.
'
** False: Copy failed.
'
** Reference instance:
'
**
'
** Blnreturn = ucopyfile ("C: \ test.exe", "d: \ test.exe", prgstate, lblstate)
'
**************************************** ********
Public   Function ucopyfile () 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, strto ,_
Addressof Copyprogressroutine, Byval   0 & , Mlngcancel, copy_file_restartable)

If Lngreturn =   0   Then
Ucopyfile
=   False
Else
Ucopyfile
=   True
End   If
End Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.