Bonjour je voudrais utiliser une progressbar avec un copyFile pour voir l'avancement de mon copier mais je sais pas du tout comment faire :cry:
Merci d'avance.
Version imprimable
Bonjour je voudrais utiliser une progressbar avec un copyFile pour voir l'avancement de mon copier mais je sais pas du tout comment faire :cry:
Merci d'avance.
Salut
Si tu es sous NT ou W200 ou XP essaye d'utiliser l'API CopyFileEx :
Pour la routine "Progress"Citation:
Envoyé par MSDNCopyFileEx
The CopyFileEx function copies an existing file to a new file. This function preserves extended attributes, OLE structured storage, NTFS alternate data streams, and file attributes. Security attributes for the existing file are not copied to the new file.
BOOL CopyFileEx(
LPCTSTR lpExistingFileName, // name of existing file
LPCTSTR lpNewFileName, // name of new file
LPPROGRESS_ROUTINE lpProgressRoutine, // callback function
LPVOID lpData, // callback parameter
LPBOOL pbCancel, // cancel status
DWORD dwCopyFlags // copy options
);
Parameters
lpExistingFileName
[in] Pointer to a null-terminated string that specifies the name of an existing file.
Windows NT/2000 or later: In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to nearly 32,000 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see File Name Conventions.
Windows 95/98/Me: This string must not exceed MAX_PATH characters.
lpNewFileName
[in] Pointer to a null-terminated string that specifies the name of the new file.
Windows NT/2000 or later: In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to nearly 32,000 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see File Name Conventions.
Windows 95/98/Me: This string must not exceed MAX_PATH characters.
lpProgressRoutine
[in] Specifies the address of a callback function of type LPPROGRESS_ROUTINE that is called each time another portion of the file has been copied. This parameter can be NULL. For more information on the progress callback function, see CopyProgressRoutine.
lpData
[in] Specifies an argument to be passed to the callback function. This parameter can be NULL.
pbCancel
[in] Pointer to a Boolean variable that can be used to cancel the operation. If this flag is set to TRUE during the copy operation, the operation is canceled.
dwCopyFlags
[in] Specifies how the file is to be copied. This parameter can be a combination of the following values. Value Meaning
COPY_FILE_FAIL_IF_EXISTS The copy operation fails immediately if the target file already exists.
COPY_FILE_RESTARTABLE Progress of the copy is tracked in the target file in case the copy fails. The failed copy can be restarted at a later time by specifying the same values for lpExistingFileName and lpNewFileName as those used in the call that failed.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information call GetLastError.
Citation:
Envoyé par MSDNCopyProgressRoutine
The CopyProgressRoutine function is an application-defined callback function used with the CopyFileEx and MoveFileWithProgress functions. It is called when a portion of a copy or move operation is completed. The LPPROGRESS_ROUTINE type defines a pointer to this callback function. CopyProgresRoutine is a placeholder for the application-defined function name.
DWORD CALLBACK CopyProgressRoutine(
LARGE_INTEGER TotalFileSize, // file size
LARGE_INTEGER TotalBytesTransferred, // bytes transferred
LARGE_INTEGER StreamSize, // bytes in stream
LARGE_INTEGER StreamBytesTransferred, // bytes transferred for stream
DWORD dwStreamNumber, // current stream
DWORD dwCallbackReason, // callback reason
HANDLE hSourceFile, // handle to source file
HANDLE hDestinationFile, // handle to destination file
LPVOID lpData // from CopyFileEx
);
Parameters
TotalFileSize
[in] Specifies the total size of the file, in bytes.
TotalBytesTransferred
[in] Specifies the total number of bytes transferred from the source file to the destination file since the copy operation began.
StreamSize
[in] Specifies the total size of the current file stream, in bytes.
StreamBytesTransferred
[in] Specifies the total number of bytes in the current stream that have been transferred from the source file to the destination file since the copy operation began.
dwStreamNumber
[in] Handle to the current stream. The first time CopyProgressRoutine is called, the stream number is 1.
dwCallbackReason
[in] Specifies the reason that CopyProgressRoutine was called. This parameter can be one of the following values. Value Meaning
CALLBACK_CHUNK_FINISHED Another part of the data file was copied.
CALLBACK_STREAM_SWITCH Another stream was created and is about to be copied. This is the callback reason given when the callback routine is first invoked.
hSourceFile
[in] Handle to the source file.
hDestinationFile
[in] Handle to the destination file
lpData
[in] The argument passed to CopyProgressRoutine by the CopyFileEx or MoveFileWithProgress function.
Return Values
The CopyProgressRoutine function should return one of the following values.
Value Meaning
PROGRESS_CONTINUE Continue the copy operation.
PROGRESS_CANCEL Cancel the copy operation and delete the destination file.
PROGRESS_STOP Stop the copy operation. It can be restarted at a later time.
PROGRESS_QUIET Continue the copy operation, but stop invoking CopyProgressRoutine to report progress.
Remarks
An application can use this information to display a progress bar that shows the total number of bytes copied as a percent of the total file size.