HowTo: Display progress dialog using IFileOperation

本小妞迷上赌 提交于 2019-12-08 03:30:31

If you just need progress dialog, then remove the reference to IOperationsProgressDialog

CopyItem only prepares the items for copying, therefore IOperationsProgressDialog::Update... will not update any UI. Actual copying begins when PerformOperations is called.

UI dialog won't show if there are only a few files, because it's done too quickly. Maybe you want to remove FOF_RENAMEONCOLLISION to make it easier for testing. This should be exact same thing as SHFileOperation.

CString srcDir = L"c:\\test\\src";
CString dstDir = L"c:\\test\\dst";

CComPtr<IFileOperation> fileOp;
fileOp.CoCreateInstance(CLSID_FileOperation);
fileOp->SetOperationFlags(FOFX_SHOWELEVATIONPROMPT);

srcDir += L"\\*";
CFileFind finder;
BOOL next = finder.FindFile(srcDir);
while (next)
{
    next = finder.FindNextFile();
    if (finder.IsDots())
        continue;

    CComPtr<IShellItem> src, dst;
    if (S_OK != SHCreateItemFromParsingName(finder.GetFilePath(), NULL, IID_PPV_ARGS(&src)))
        continue;

    if (S_OK != SHCreateItemFromParsingName(dstDir, NULL, IID_PPV_ARGS(&dst)))
        continue;

    fileOp->CopyItem(src, dst, 0, NULL);
}

MessageBox(L"nothing copied so far...");
hr = fileOp->PerformOperations();
MessageBox(L"done...");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!