福施福

VC项目开发中实现了一个利用winrar解压文件功能,程序代码片段如下:

int icount=m_LC.GetItemCount(); 
// CString cmd_str; 
// cmd_str="C:\Program Files\WinRAR\WinRAR.exe"; 
// cmd_str=cmd_str+" e "; 
// cmd_str=cmd_str+"C:\aa.zip"; 
// cmd_str=cmd_str+" C:\aa\"; 
//system(cmd_str); 
//::she 
m_progress.SetRange(1,icount); 
for(int i=0;i<icount;i++) 

//cmd_str=" "; 
//cmd_str="c:\\Program Files\\WinRAR\\WinRAR.exe e "; 
//cmd_str+=file_list.GetItemText(i,1); 
//cmd_str+=" "; 
//cmd_str+=Get_drection(file_list.GetItemText(i,1)); 
//cmd_str+="\\"; 
//MessageBox(cmd_str); 
//::ShellExecuteEx(cmd_str); 
//::system(cmd_str); 
//this->m_test=cmd_str; 
if(check(m_LC.GetItemText(i,1))) 

CString str="\""+m_LC.GetItemText(i,1)+"\""; 
str+=" \""+Get_drection(m_LC.GetItemText(i,1))+"\\\""; 
str=get_direct()+" x -o+ -IBCK "+str; 
PROCESS_INFORMATION   pidInfo; 
STARTUPINFO     startInfo; 
BOOL b; 
char *buf=" "; 
startInfo.cb           =   sizeof(STARTUPINFO); 
startInfo.lpReserved   =   NULL; 
startInfo.lpTitle     =   NULL; 
startInfo.lpDesktop   =   NULL; 
startInfo.dwX         =   0; 
startInfo.dwY         =   0; 
startInfo.dwXSize     =   0; 
startInfo.dwYSize     =   0; 
startInfo.dwXCountChars     =   0; 
startInfo.dwYCountChars     =   0; 
startInfo.dwFlags     =   STARTF_USESTDHANDLES; 
startInfo.wShowWindow   =   0;   //SW_SHOWDEFAULT; 
startInfo.lpReserved2   =   NULL; 
startInfo.cbReserved2   =   0; 
startInfo.hStdInput   =   GetStdHandle(STD_INPUT_HANDLE); 
startInfo.hStdOutput   =   GetStdHandle(STD_OUTPUT_HANDLE); 
startInfo.hStdError   =   GetStdHandle(STD_ERROR_HANDLE);   
b=CreateProcess(NULL,str.GetBuffer(0),NULL,NULL,TRUE,CREATE_NO_WINDOW,NULL,NULL,&startInfo,&pidInfo); 
if(!b){ 
  AfxMessageBox("failed"); 
  return; 

str.ReleaseBuffer(); 
WaitForSingleObject(pidInfo.hProcess,INFINITE); 
CloseHandle(pidInfo.hProcess); 
CloseHandle(pidInfo.hThread); 

else 

MessageBox("该文件非压缩文件哦::"+m_LC.GetItemText(i,1)); 

m_progress.SetPos(i+1); 

原文地址:https://www.cnblogs.com/dengyigod/p/2598504.html