不了解com,高手指点一下

wateryh 2010-07-02 03:29:07
下面的函数是从网上copy的,
把zip文件解压,很管用。

现在的问题是,在解压的时候,会弹出一个正在复制的对话框。
要去掉这个对话框,修改哪里啊


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 = 16+4; // Do not display a progress dialog box ~ This will not work properly!


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;
}
...全文
144 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
j307533688 2012-07-24
  • 打赏
  • 举报
回复
LZ,
1.folder 的copyhere方法, 进度条的操作, 对compress *.zip文件 可能没有效果;

2.不用纠结那个值了,FOF_UI, 设置成这个,你跳进去就知道了
wateryh 2010-07-02
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wateryh 的回复:]
VariantInit(&vOpt);
vOpt.vt = VT_I4;
vOpt.lVal = 16+4; // Do not display a progress dialog box ~ This will not work properly!

上面的的那个值(16+4),是在哪里可以找到它代表的意思啊
[/Quote]

这个是怎么找到的啊
我在msdn里面搞了一下午没找到,汗...
踏实每一步 2010-07-02
  • 打赏
  • 举报
回复
16+4;改成16
雪影 2010-07-02
  • 打赏
  • 举报
回复
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.

wateryh 2010-07-02
  • 打赏
  • 举报
回复
VariantInit(&vOpt);
vOpt.vt = VT_I4;
vOpt.lVal = 16+4; // Do not display a progress dialog box ~ This will not work properly!

上面的的那个值(16+4),是在哪里可以找到它代表的意思啊
stonewater 2010-07-02
  • 打赏
  • 举报
回复
看来是不支持不显示窗口,
悲剧了
雪影 2010-07-02
  • 打赏
  • 举报
回复
VariantInit(&vOpt);
vOpt.vt = VT_I4;
vOpt.lVal = 16+4; // Do not display a progress dialog box ~ This will not work properly!

这里是设置不显示进度条的,但不能保证正常工作

lz悲剧了~~

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧