Salut,
une solution (surement pas la meilleure) :
bool bModal = true;
TCHAR szExe[] = _T("notepad.exe unFichier.txt");
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
ZeroMemory(&pi, sizeof(pi));
si.cb = sizeof(si);
// Demarre process notepad
if( CreateProcess(NULL, szExe, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) )
{
// Simule un comportement modal de notepad
if( bModal )
{
WaitForSingleObject(pi.hProcess, INFINITE);
}
// Ou un comportement non modal
else
{
DWORD dwExit;
MSG msg;
while( true )
{
if( !GetExitCodeProcess(pi.hProcess, &dwExit) )
break;
if( dwExit == STILL_ACTIVE )
{
if( PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
elsebreak;
}
}
// Libère process
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}