|
-
August 2nd, 2010, 08:48 AM
#4
Re: c++ to launch a program
You could write a batch programmatically and launch it with CreateProcess
Code:
STARTUPINFO si = { 0 };
si.cb = sizeof(si);
si.showWindow = SW_HIDE;
PROCESS_INFO pi = { 0 };
std::ofstream batch("temp.bat");
batch << "@echo off" << std::endl
<< "set __COMPAT_LAYER=Win98" << std::endl
<< executable_to_invoke << std::endl;
batch.close();
CreateProcess(NULL, "call temp.bat", NULL, NULL, FALSE,
DETACHED_PROCESS, NULL, NULL, &si, &pi);
...
where 'executable_to_invoke' is a string variable that contains the filename (full path if not in working directory) of the executable you want to launch.
After CreateProcess you could wait for the process handle pi.hProcess (calling WaitForSingleObject) if your launcher should wait until execution of the batch has ended. If not, you at least may wait until the executable was launched from batch, e. g. by enumerating windows or processes until you found the newly started program. If you could retrieve the window handle of the new process that way, you also could call 'ShowWindow(hwndProc, SW_MAXIMIZE);' to get it maximized.
Regards, Alex
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|