解压缩:
将 CUnrarDll.h 及 cpp 添加入你的工程
将 unrar.dll 放入你的程序生成目录
代码:
#include "CUnrarDLL.h"
需要解压缩的地方:
CUnrarDLL unrarObj;
unrarObj.OpenRARFile(yourfilepathname);
unrarObj.SetOutputDirectory(yourdestdir);
unrarObj.UnRARArchive();
附加:
如果需要压缩成rar,则可以通过指令调用winrar进行,下面代码可供参考
其中CGP::_AppPath 为应用程序所在目录
该目录下的Rar.lst定制了要压缩的文件,这样可以排除一些没必要压缩的,可以多行和使用通配符,参见给的rar.lst。
BOOL CMainFrame::MakeRar(CString fn,CString filepath)
{
CString winrarpath=_RegGetString(HKEY_LOCAL_MACHINE,
"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\winrar.exe",
"Path");
if(winrarpath.IsEmpty())
{
_MSGBOX("无法找到 Winrar 的执行文件,因此无法压缩考生目录!");
return FALSE;
}
//copy sfx to winrar path
if(fn.IsEmpty())
return FALSE;
CString strPath;
GetCurrentDirectory(MAX_PATH,strPath.GetBuffer(MAX_PATH));
strPath.ReleaseBuffer();
SetCurrentDirectory(filepath);
if(_ShellExecuteWait(winrarpath+"\\winrar.exe a -r \""+fn+"\" @\""+CGP::_AppPath+"Rar.lst\"",filepath))
{
SetCurrentDirectory(strPath);
return TRUE;
}
else
{
SetCurrentDirectory(strPath);
return FALSE;
}
}
//启动程序并等待程序结束
bool _ShellExecuteWait(CString pFileNameWithPara,CString pPath)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line).
(LPSTR)(LPCTSTR)pFileNameWithPara,// Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
(LPSTR)(LPCTSTR)pPath, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
_MSGBOX("不能启动"+pFileNameWithPara);
return false;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return true;
}
如果要压缩成自解压包,可以参见如下代码
_ShellExecuteWait(winrarpath+"\\winrar.exe a \""+fn+"\" @\""+CGP::_AppPath+"Rar.lst\""+
" -sfx"+
" -z\""+CGP::_AppPath+"Rar.ins\""+
" -iicon\""+CGP::_AppPath+"Skins\\Rar.ico\""+
" -iimg\""+CGP::_AppPath+"Skins\\RarBK.bmp\"",CGP::_AppPath);
主要是添加了-sfx 参数,设定了图标和自解压包的背景图,自解压的指令可以放置在 rar.ins 文件里,路边其实就是手动生成自解压时的“注释”部分,包含了自释放的默认路径,生成的快捷方式,版权提示等等。

BimyuIO
- 粉丝: 2
最新资源
- 2020年第三季度网站自查自评报告.docx
- 电气自动化专业建设十三五规划.doc
- 互联网广告不能一键关闭怎么处罚?.doc
- 电子商务师考试试题及答案.docx
- 学校校园网络组建方案.doc
- 国家开发银行(贵州省分行)国家开发银行贵州省分行助学贷款毕业学生诚信网络答题试卷(202112141.pdf
- BP人工神经网络的基本原理模型与实例.pptx
- 国家开放大学电大专科《网络信息编辑》期末试题标准题库.docx
- 软件公司工作总结.doc
- 手机软件自动化测试介绍.ppt
- 网络研修心得体会.doc
- 随机选择问题算法说明.pdf
- 软件工程导论-住房管理系统-实验指导.doc
- 项目管理及软件测试实验指导书.doc
- 基于单片机的红外测距系统设计开题报告.doc
- 广东省干部培训网络学院-2类-社会主义中国化的历程和发展方向--考试-答案-(90分).doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


