现在的位置: 首页 > 自动控制 > 工业·编程 > 正文

VC++ 调用7z.exe 命令行参数实现简单的压缩、解压

2013-12-22 06:39 工业·编程 ⁄ 共 1195字 ⁄ 字号 暂无评论

压缩:
void CTestXXXDlg::OnXXX()
{
// TODO: Add your control notification handler code here
// 压缩程序
CString str7zPath;
str7zPath = _T("C:\\Program Files\\7-Zip\\7z.exe");
CString strFilePath = _T("D:\\DirRoot\\MemTest.exe");//要压缩文件的绝对路径
CString strSaveDir;
strSaveDir = strFilePath.Left(strFilePath.ReverseFind(_T('\\')));
CString strSaveName;
strSaveName = strSaveDir+_T("\\MemTest.7z");
CString strP;//压缩参数(-t为压缩类型)
    strP.Format(_T("a -t7z %s %s"),strSaveName,strFilePath);
    HINSTANCE hRet = ShellExecute(NULL,"open",str7zPath,strP,NULL,SW_HIDE);//SW_SHOW显示对话框
if (!hRet)

MessageBox(_T("压缩失败!"),_T("提示"),MB_ICONERROR);
    }else
{
MessageBox(_T("压缩成功!"),_T("提示"),MB_ICONINFORMATION);
}
}

解压:
void CTestXXXDlg::OnXXX()
{
// TODO: Add your control notification handler code here
CString str7zPath;
str7zPath = _T("C:\\Program Files\\7-Zip\\7z.exe");
CString strZipPath = _T("D:\\DirRoot\\MemTest.7z");//要解压文件的绝对路径
CString strSaveDir;
strSaveDir = strZipPath.Left(strZipPath.ReverseFind(_T('\\')));
CString strP;//解压参数
    strP.Format(_T("e %s -o%s -y"),strZipPath,strSaveDir);
HINSTANCE hRet =ShellExecute(NULL,"open",str7zPath,strP,NULL,SW_HIDE);//SW_SHOW显示对话框
if (!hRet) 

MessageBox(_T("解压失败!"),_T("提示"),MB_ICONERROR); 
    }else
{
MessageBox(_T("解压成功!"),_T("提示"),MB_ICONINFORMATION);
}
}

给我留言

留言无头像?