Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting visual C++ to start a external program

Status
Not open for further replies.

SmileeTiger

Programmer
Mar 13, 2000
200
US
Does anyone know how I could get VC++ to run a external program?<br>
<br>
When I click on a button I want the program to start running in another window.<br>
<br>
Anyone have any ideas??
 
Hi I figured it out!!<br>
<br>
STARTUPINFO si;<br>
PROCESS_INFORMATION pi;<br>
<br>
// Execute the command with a call to the CreateProcess API call.<br>
memset(&si,0,sizeof(STARTUPINFO));<br>
si.cb = sizeof(STARTUPINFO);<br>
si.wShowWindow = SW_SHOW;<br>
CreateProcess(NULL,&quot;c:\\com2io2.exe&quot;,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);<br>
CloseHandle(pi.hThread);<br>
CloseHandle(pi.hProcess);
 
or if it is a windows application you just have to use the<br>
WinExec("Notepad.exe", SW_SHOW) command.<br>
<br>
Whereas Notepad.exe is the name of the executable file.<br>
Could be Whatever.exe.
 
Using the code I specifed above does anyone know of a way to have the window always appear ontop? Right now I have the program started in the on initial updat section for my program. This program is started when the application first starts
 
I'm not sure what you mean exactly, so ignore this if it doesn't solve your problem.&nbsp;&nbsp;Are you looking for a way to wait until the program that you are starting (com2io2.exe) ends before continuing so that other windows in your mainline application don't pop up over it?&nbsp;&nbsp;If so, here is what I would do using your example above:<br><br>&nbsp;&nbsp;&nbsp;si.cb = sizeof(STARTUPINFO);<br>&nbsp;&nbsp;&nbsp;si.wShowWindow = SW_SHOW;<br>&nbsp;&nbsp;&nbsp;BOOL ret = CreateProcess (NULL, &quot;c:\\com2io2.exe&quot;,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);<br>&nbsp;&nbsp;&nbsp;if(ret)<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WaitForSingleObject(pi.hProcess,INFINITE); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CloseHandle(pi.hProcess);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CloseHandle(pi.hThread);<br>&nbsp;&nbsp;&nbsp;}<br><br>This way, the task (com2io2.exe) can do its job before the rest of your application goes on it's way...<br><br>Hope this helps!<br> <p>Pat Gleason<br><a href=mailto:gleason@megsinet.net>gleason@megsinet.net</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top