I’m trying to get a progress dialog to display for my copy operation in some sample code. I’m using IFileOperation because I found that using SHFileOperation will not display a progress dialog if the files have already been copied to the target location. My hope is that IFileOperation is a little more sophisticated and can handle that situation. Here’s the sample code I’ve tried….
CComPtr<IOperationsProgressDialog> opProgressDlg;
HRESULT hr = opProgressDlg.CoCreateInstance(CLSID_ProgressDialog);
CComPtr<IFileOperation> fileOp;
hr = fileOp.CoCreateInstance(CLSID_FileOperation);
hr = fileOp->SetOperationFlags(FOF_RENAMEONCOLLISION | FOFX_PRESERVEFILEEXTENSIONS | FOFX_NOMINIMIZEBOX);
hr = fileOp->SetProgressDialog(opProgressDlg);
hr = opProgressDlg->StartProgressDialog(m_hWnd, OPPROGDLG_DEFAULT);
hr = opProgressDlg->SetMode(PDM_DEFAULT);
hr = opProgressDlg->SetOperation(SPACTION_COPYING);
oldDirectory += _T("*.*");
CFileFind finder;
BOOL bWorking = finder.FindFile(oldDirectory);
while (bWorking)
{
bWorking = finder.FindNextFile();
if (finder.IsDots())
continue;
CString name = finder.GetFilePath();
IShellItem *psiFrom = nullptr;
hr = SHCreateItemFromParsingName(CT2CW(name), NULL, IID_PPV_ARGS(&psiFrom));
IShellItem *psiTo = NULL;
hr = SHCreateItemFromParsingName(CT2CW(newDirectory), NULL, IID_PPV_ARGS(&psiTo));
hr = fileOp->CopyItem(psiFrom, psiTo, CT2CW(finder.GetFileName()), NULL);
//hr = opProgressDlg->UpdateLocations(psiFrom, psiTo, psiTo);
}
opProgressDlg->StopProgressDialog();
hr = fileOp->PerformOperations();
The sample is trying to copy all files and folders from one location (oldDirectory) to another (newDirectory). The copy operation does copy everything correctly. I’m looking for help in getting the progress dialog to display during the operation. According to IFileOperation, I should be able to set the progress dialog through IOperationsProgressDialog. The documentation for this is extremely thin. I have not been able to find any samples showing how to fit the two together. Does anyone have experience with these two interfaces?