写个小程序吧,实际上CopyFileEx也就是可以在copy过程中给点信息而已。 #include <windows.h> #include <conio.h> #include <stdio.h>DWORD CALLBACK CopyProgress( LARGE_INTEGER TotalFileSize, // total file size, in bytes LARGE_INTEGER TotalBytesTransferred, // total number of bytes transferred LARGE_INTEGER StreamSize, // total number of bytes for this stream LARGE_INTEGER StreamBytesTransferred, // total number of bytes transferred for // this stream DWORD dwStreamNumber, // the current stream DWORD dwCallbackReason, // reason for callback HANDLE hSourceFile, // handle to the source file HANDLE hDestinationFile, // handle to the destination file LPVOID lpData // passed by CopyFileEx ) { printf("%08X:%08X of %08X:%08X copied.\n",TotalBytesTransferred.HighPart,TotalBytesTransferred.LowPart,TotalFileSize.HighPart,TotalFileSize.LowPart); return PROGRESS_CONTINUE; //还有以下几种返回值。 //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. } int main(int argc,char **argv) { int Cancel=FALSE; if(argc!=3) { printf("CopyEx Src Dst\n"); return 0; } if(!CopyFileEx(argv[1],argv[2],(LPPROGRESS_ROUTINE)CopyProgress,NULL,&Cancel,COPY_FILE_FAIL_IF_EXISTS)) { printf("CopyFileEx() failed.\n"); return 0; }
Flags可以是以下值之一
COPY_FILE_FAIL_IF_EXISTS//如果目标文件已存在即退出
COPY_FILE_RESTARTABLE//拷贝失败的时候可以重新开始
因为,我想监控整个文件复制过程。
大家帮帮忙吧,问题解决了,马上给分。 谢谢。
#include <windows.h>
#include <conio.h>
#include <stdio.h>DWORD CALLBACK CopyProgress(
LARGE_INTEGER TotalFileSize, // total file size, in bytes
LARGE_INTEGER TotalBytesTransferred,
// total number of bytes transferred
LARGE_INTEGER StreamSize, // total number of bytes for this stream
LARGE_INTEGER StreamBytesTransferred,
// total number of bytes transferred for
// this stream
DWORD dwStreamNumber, // the current stream
DWORD dwCallbackReason, // reason for callback
HANDLE hSourceFile, // handle to the source file
HANDLE hDestinationFile, // handle to the destination file
LPVOID lpData // passed by CopyFileEx
)
{
printf("%08X:%08X of %08X:%08X copied.\n",TotalBytesTransferred.HighPart,TotalBytesTransferred.LowPart,TotalFileSize.HighPart,TotalFileSize.LowPart);
return PROGRESS_CONTINUE;
//还有以下几种返回值。
//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.
}
int main(int argc,char **argv)
{
int Cancel=FALSE;
if(argc!=3)
{
printf("CopyEx Src Dst\n");
return 0;
}
if(!CopyFileEx(argv[1],argv[2],(LPPROGRESS_ROUTINE)CopyProgress,NULL,&Cancel,COPY_FILE_FAIL_IF_EXISTS))
{
printf("CopyFileEx() failed.\n");
return 0;
}
// getch();//这个CopyFileEx好像是同步的,不必加getch了。
return 0;
}
我自己也解决了这个问题,不过分我还是给你了,看看吧。