vItem Required. The item or items to copy. This can be a string that represents a file name, a FolderItem object, or a FolderItems object.
vOptions Optional. Options for the copy operation. This value can be zero or a combination of the following values. These values are based upon flags defined for use with the fFlags member of the C++ SHFILEOPSTRUCT structure. These flags are not defined as such for Microsoft Visual Basic, Visual Basic Scripting Edition (VBScript), or Microsoft JScript, so you must define them yourself or use their numeric equivalents.
4 Do not display a progress dialog box.
8 Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.
16 Respond with "Yes to All" for any dialog box that is displayed.
64 Preserve undo information, if possible.
128 Perform the operation on files only if a wildcard file name (*.*) is specified.
256 Display a progress dialog box but do not show the file names.
512 Do not confirm the creation of a new directory if the operation requires one to be created.
1024 Do not display a user interface if an error occurs.
2048 Version 4.71. Do not copy the security attributes of the file.
4096 Only operate in the local directory. Don't operate recursively into subdirectories.
9182 Version 5.0. Do not copy connected files as a group. Only copy the specified files.
bool UnZipFolder(LPCTSTR zipFile,LPCTSTR destination)
{ DWORD strlen = 0;
HRESULT hResult;
IShellDispatch *pISD;
Folder *pToFolder = NULL;
Folder *pFromFolder = NULL;
FolderItems *pFolderItems = NULL;
FolderItem *pItem = NULL;
VARIANT vDir, vFile, vOpt;
BSTR strptr1, strptr2;
CoInitialize(NULL);
bool bReturn = false;
hResult = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER,
IID_IShellDispatch, (void **)&pISD);
if(FAILED(hResult))
{
return bReturn;
}
VariantInit(&vOpt);
vOpt.vt = VT_I4;
vOpt.lVal = 4; // 这里改成4了依然出现复制过程的对话框,不想要对话框如何改
CString strZipFile(zipFile);
CString strDestination(destination);
strptr1 = strZipFile.AllocSysString();
strptr2 = strDestination.AllocSysString();
VariantInit(&vFile);
vFile.vt = VT_BSTR;
vFile.bstrVal = strptr1;
hResult = pISD->NameSpace(vFile, &pFromFolder);
VariantInit(&vDir);
vDir.vt = VT_BSTR;
vDir.bstrVal = strptr2;
hResult = pISD->NameSpace(vDir, &pToFolder);
if(S_OK == hResult)
{
hResult = pFromFolder->Items(&pFolderItems);
if(SUCCEEDED(hResult))
{
long lCount = 0;
pFolderItems->get_Count(&lCount);
IDispatch* pDispatch = NULL;
pFolderItems->QueryInterface(IID_IDispatch,(void**)&pDispatch);
VARIANT vtDispatch;
VariantInit(&vtDispatch);
vtDispatch.vt = VT_DISPATCH;
vtDispatch.pdispVal = pDispatch;//cout << "Extracting files ...\n";
hResult = pToFolder->CopyHere(vtDispatch,vOpt);
if(hResult != S_OK) return false;
//Cross check and wait until all files are zipped!
FolderItems* pToFolderItems;
hResult = pToFolder->Items(&pToFolderItems);if(S_OK == hResult)
{
long lCount2 = 0; hResult = pToFolderItems->get_Count(&lCount2);
if(S_OK != hResult)
{
pFolderItems->Release();
pToFolderItems->Release();
SysFreeString(strptr1);
SysFreeString(strptr2);
pISD->Release();
CoUninitialize();
return false;
}
//Use this code in a loop if you want to cross-check the items unzipped.
/*if(lCount2 != lCount)
{
pFolderItems->Release();
pToFolderItems->Release();
SysFreeString(strptr1);
SysFreeString(strptr2);
pISD->Release();
CoUninitialize();
return false;
}*/bReturn = true;
} pFolderItems->Release();
pToFolderItems->Release();
}pToFolder->Release();
pFromFolder->Release();
}
//cout << "Over!\n";
SysFreeString(strptr1);
SysFreeString(strptr2);
pISD->Release();
CoUninitialize();
return bReturn;
}
解决方案 »
- 求一个没用过的控件的使用方法
- 请问mfc中哪种情况需要手动添加消息映射?
- 单文档创建多视图
- 大家帮我看看问题出在哪里(HttpQueryInfo相关的问题)
- 为什么我的程序的这段StretchDIBits总是返回的是0???
- 100分求做报表的源程序示例,分不够再加!!
- 求源码,用CListCtrl和CComboBox实现文件列表的功能
- 如何在vc程序中实现让用户自定义菜单的快捷键和shortcut的功能?
- 我的学习笔记。大家共同学习。
- SDK问题?消息WM_ERASEBKGND的处理,能解释一下背景的处理吗?问题在下面,谢谢!
- 我想问一下,GDI+有什么办法把字体路径描出来。
- 如何单步调试CLR创建的windows服务啊
WinZip?
VariantInit(&vOpt);
vOpt.vt = VT_I4;
vOpt.lVal = 4; // 这里改成4了依然出现复制过程的对话框,不想要对话框如何改
修改后依然提示复制过程的对话框!