MFC中关于子进程创建和关闭操作


创建子进程  

PROCESS_INFORMATION ProcessInfo; STARTUPINFO StartupInfo;
//This is an [in] parameter ZeroMemory(&StartupInfo, sizeof(StartupInfo)); StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field //processHandle = CreateProcess(_T(".\\MyTwain\\Debug\\MyTwain.exe"), NULL,NULL,NULL,FALSE,0,NULL,NULL,&StartupInfo,&ProcessInfo); if(CreateProcess(_T(".\\MyTwain\\Debug\\MyTwain.exe"), NULL,NULL,NULL,FALSE,0,NULL,NULL,&StartupInfo,&ProcessInfo)) { // hProcess = GetCurrentProcess(); KillTimer(1); SetTimer(1,1000,NULL); //WaitForSingleObject(ProcessInfo.hProcess,INFINITE); //CloseHandle(ProcessInfo.hThread); //CloseHandle(ProcessInfo.hProcess); //MessageBox(_T("1")); //HANDLE MyProcess = GetCurrentProcess(); //TerminateProcess(ProcessInfo.hProcess, 0); } else { MessageBox(L"The process could not be started..."); }

关闭子进程:

在类视图-》CXXXDlg函数点击鼠标右键-》消息-》WM_DESTROY,添加ondestory函数

TerminateProcess(ProcessInfo.hProcess,0);//第一个参数为要关闭的进程的句柄
 

 



智能推荐

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告