如下代码是微软自带的解压缩,在MFC程序中实现测试没有问题,但现在遇到两个问题
1.第一个想实现在解压的时候去掉正在复制的对话框,如何实现,搜了很多资料说把程序中的vOpt.lVal = 16+4;改为vOpt.lVal = 4;但也没有效果,解压复制的进程对话框仍然存在!
2.第二个我想问一下是否能够实现在程序未解压前就能够算出压缩后的文件夹大小?想了半天,无头绪!
备注:都是ZIP压缩文件
bool CMyDlg::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);//初始化COM
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 = 16+4; // Do not display a progress dialog box ~ This will not work properly!
CString strZipFile(zipFile);
CString strDestination(destination);
strptr1 = strZipFile.AllocSysString(); //将CSTRING 转换为BSTR
// int b=strptr1->get;
strptr2 = strDestination.AllocSysString();
VariantInit(&vFile); //就是初期化为VT_EMPTY
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;
// int b=strZipFile(vtDispatch);
//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;
}
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课