OK, this code works with notepad:
it will put your executable in the foreground,
in the clients rectangle:
STARTUPINFO si;
PROCESS_INFORMATION pi;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW |
STARTF_USEPOSITION |
STARTF_USESIZE;
si.wShowWindow = SW_SHOW;
CRect r;
AfxGetMainWnd()->GetClientRect( r );
ClientToScreen( &r );
si.dwX = r.left;
si.dwY = r.top;
si.dwXSize = r.right - r.left;
si.dwYSize = r.bottom - r.top;
CString exe = "c:\\windows\\notepad.exe";
CString dir = "c:\\";
CreateProcess( exe , NULL , NULL , NULL , FALSE , 0 , NULL , dir , &si , &pi );
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
about: TerminateProcess( pi.hProcess , 9 );
This should work too, i use it all the time.
Be sure the pi is the same pi as in the CreateProcess.