我想通过mfc调用进程,但我需要新的exe必须像子对话框一样假装。因此,如果新的exe文件无法关闭,则用户不应该进入主进程(对话框)吗?
是的。当您打开新进程时,必须等待用户关闭子进程,然后才能使用WaitForSingleObject(pi.hProcess,INFINITE);
以下代码...
if( !CreateProcess( NULL, // No module name (use command line).
exePath, // Command line.
NULL,// Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
NORMAL_PRIORITY_CLASS,// No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
cout << "Unable to create\n";}
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return false;
}
WaitForSingleObject( pi.hProcess, INFINITE );// wait user till close exe(after close child process then go parent process)
return true;
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句