Hi,
I am trying to make Backup program, that copy files from one location to another one, but I don't know how to allow user to cancel this operation.
The code that I use is:
Thank you
I am trying to make Backup program, that copy files from one location to another one, but I don't know how to allow user to cancel this operation.
The code that I use is:
Code:
Public Class Form1
Private Delegate Function CopyProgressRoutine(ByVal totalFileSize As Int64, ByVal totalBytesTransferred As Int64, ByVal streamSize As Int64, ByVal streamBytesTransferred As Int64, ByVal dwStreamNumber As Int32, ByVal dwCallbackReason As Int32, ByVal hSourceFile As Int32, ByVal hDestinationFile As Int32, ByVal lpData As Int32) As Int32
Private Declare Auto Function CopyFileEx Lib "kernel32.dll" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal lpProgressRoutine As CopyProgressRoutine, ByVal lpData As Int32, ByVal lpBool As Int32, ByVal dwCopyFlags As Int32) As Int32
Private Function CopyProgress(ByVal totalFileSize As Int64, ByVal totalBytesTransferred As Int64, ByVal streamSize As Int64, ByVal streamBytesTransferred As Int64, ByVal dwStreamNumber As Int32, ByVal dwCallbackReason As Int32, ByVal hSourceFile As Int32, ByVal hDestinationFile As Int32, ByVal lpData As Int32) As Int32
ProgressBar1.Value = Convert.ToInt32(totalBytesTransferred / totalFileSize * 100)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cpr As New CopyProgressRoutine(AddressOf CopyProgress)
CopyFileEx("C:\myFile.dll", "D:\myFile.dll", cpr, 0, 0, 0)
End Sub
End Class
Comment