VC 粉丝

VC知识点记录

1.MoveFileWithProgress 功能与 MoveFileEx 是相同的,只不过 MoveFileWithProgress 允许你提供一个接收移动进度消息的回调函数。 

 


MoveFile 函数移动已存在的文件或文件夹,包括它的子文件和文件夹。只能在同一目录或volume(卷)下移动


MoveFileEx or MoveFileWithProgress  指定如何去移动文件。可以在不同volume下移动,但必须指定MOVEFILE_COPY_ALLOWED,但有时移动不成功,会出现error(5)的错误,这跟系统的读取权限有关。

 

MoveFileTransacted 允许执行事务处理的操作。

    #define        _WIN32_WINNT    0x0500            // 不加这个不同通过编译
#include <windows.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
)
   {
        static int nRecord = 0;
        nRecord++;
        printf("回调次数:%d    已传输:%08X:%08X    文件大小:%08X:%08X ",
        nRecord,
        TotalBytesTransferred.HighPart,
        TotalBytesTransferred.LowPart,
        TotalFileSize.HighPart,
        TotalFileSize.LowPart);
        return PROGRESS_CONTINUE;
   }

int main(int argc, char* argv[])
   {
        if(argc!=3)
        {
            printf("用法:命令 源文件 目标文件");
            return 0;
        }

        if(!CopyFileEx(argv[1],argv[2],(LPPROGRESS_ROUTINE)CopyProgress,NULL,FALSE,COPY_FILE_FAIL_IF_EXISTS))
        {
            printf("CopyFileEx() failed.");
            return 0;
        }
        return 0;
   }

 

 

posted on 2009-06-29 20:01  VC 粉丝  阅读(411)  评论(0编辑  收藏  举报

导航