标签:sizeof col ref dev gets 需要 error dir direct
void CMyCompress:: CreateBat(CString BatPath,CString ArjPath,
CString BatName,CString ArjFileName,
CString TempPath,CString ExitFlag,BOOL out)
{
LPTSTR lpBuffer;
UINT uSize;
HANDLE hHeap;
uSize=(GetCurrentDirectory(0,NULL))*sizeof(TCHAR);
hHeap=GetProcessHeap();
lpBuffer=(LPSTR)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,uSize);
GetCurrentDirectory(uSize,lpBuffer);
//得知当前目录信息,以便根据需要变换目录
if (lpBuffer!=BatPath) //diferent dir
SetCurrentDirectory(BatPath);
CStdioFile f;
CFileException e;
if (!f.Open( BatName, CFile::modeCreate|CFile::modeWrite, &e))
//以BatName的内容创建一个批处理文件
{
AfxMessageBox("不能创建文件"+BatName);
return ;
}
char density[6];
sprintf(density,"%d",mTotalBytes);
---- //mTotalBytes 是 由 其 他 函 数 设 定 的 变 量, 用 于 记 录 用 于 拷 入 或 拷 出 文 件 的 磁 盘 所 具 有 的 最 大 可 用 空 间
CString Density=density; CString string; if (out)//说明是生成做压缩工作的批处理文件 string="arj a -v"+Density; else //说明是生成做解压缩工作的批处理文件 string="arj e -v"+Density; string+=" ..//"+ArjPath+"//"+ArjFileName+" "; if (out) string=string+"..//"+TempPath+"//*.* -y -jm/n"; else string=string+"..//"+TempPath+"// -y -jm/n"; f.WriteString(string); string="dir >"+ExitFlag+"/n"; f.WriteString(string); f.Close(); SetCurrentDirectory(lpBuffer);//回复到原来的目录下 }
---- 该 函 数 执 行 后, 将 生 成 一 个 批 处 理 文 件, 内 容 大 致 是:
---- ARJ A -V1440 压 缩 后 文 件 的 路 径 名+ 文 件 名 被 压 缩 文 件 的 路 径 名+ 文 件 名 -Y -JM
---- DIR > 临 时 文 件 名
---- 或 者 是:
---- ARJ E -V1440 被 解 压 缩 文 件 的 路 径 名+ 文 件 名 解 压 缩 后 文 件 的 路 径 名+ 文 件 名 -Y -JM
---- DIR > 临 时 文 件 名
void CMyCompress::RunBat(CString
BatPath,CString fileName,CString ExitFlag)
{
CString lpApplicationName=BatPath+"//"+fileName;
// 进 程 执 行 的 应 用 程 序 的 完 全 路 径 名
STARTUPINFO StartupInfo;// 创 建 进 程 所 需 的 信 息 结 构 变 量
GetStartupInfo(&StartupInfo);
StartupInfo.lpReserved=NULL;
StartupInfo.lpDesktop=NULL;
StartupInfo.lpTitle=NULL;
StartupInfo.dwX=0;
StartupInfo.dwY=0;
StartupInfo.dwXSize=200;
StartupInfo.dwYSize=300;
StartupInfo.dwXCountChars=500;
StartupInfo.dwYCountChars=500;
StartupInfo.dwFlags=STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow=SW_HIDE;
// 说 明 进 程 将 以 隐 藏 的 方 式 在 后 台 执 行
StartupInfo.cbReserved2=0;
StartupInfo.lpReserved2=NULL;
StartupInfo.hStdInput=stdin;
StartupInfo.hStdOutput=stdout;
StartupInfo.hStdError=stderr;
LPTSTR lpBuffer;
UINT uSize;
HANDLE hHeap;
uSize=(GetCurrentDirectory(0,NULL))*sizeof(TCHAR);
hHeap=GetProcessHeap();
lpBuffer=(LPSTR)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,uSize);
GetCurrentDirectory(uSize,lpBuffer);
// 得 知 当 前 目 录 信 息, 以 便 根 据 需 要 变 换 目 录
if (lpBuffer!=BatPath) //diferent dir
SetCurrentDirectory(BatPath);
// 创 建 进 程
if (CreateProcess(lpApplicationName,NULL,NULL,
NULL,FALSE,CREATE_DEFAULT_ERROR_MODE,
NULL,NULL,&StartupInfo,&pro_info))
{
MSG Message;
DeleteFile(ExitFlag);
SetTimer(1,100,NULL);// 设 置 计 时 器
Search=TRUE;
while(Search) {
if (::PeekMessage(&Message,NULL,0,0,PM_REMOVE)) {
::TranslateMessage(&Message);
::DispatchMessage(&Message);
}
}
// 进 程 结 束 前 后 的 处 理 工 作
DWORDExitCode;
if (!GetExitCodeProcess(pro_info.hProcess,&ExitCode))
AfxMessageBox("GetExitCodeProcess is Failed!");
if (!TerminateProcess(pro_info.hProcess,(UINT)ExitCode))
// 终 止 进 程
AfxMessageBox("TerminateProcess is Failed!");
if (!CloseHandle(pro_info.hProcess))
// 释 放 被 终 止 进 程 的 句 柄
AfxMessageBox("CloseHandle is Failed!");
KillTimer(1);// 撤 消 计 时 器
}
else AfxMessageBox("Process Is Not Created!");
SetCurrentDirectory(lpBuffer);// 回 复 到 原 来 的 目 录 下
}
void CMyCompress::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CFile file;
CFileException Error;
if (file.Open(ExitFlag,CFile::modeRead,&Error)) {
Search=FALSE;
file.Close();
}
}
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://www.cnblogs.com/captainbed
标签:sizeof col ref dev gets 需要 error dir direct
原文地址:https://www.cnblogs.com/swhchwhdh/p/10165006.html