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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to run an external program. 1

Status
Not open for further replies.

Jouster

Programmer
Dec 4, 2000
82
US
I'm trying to write a program that can run an .exe program and can shut it down when it needs to. I'd like it to also run in my client window. I've searched through MSDN and didnt really find what I was loojing for( if I was looking in the right place)...if someone could point me in the direction of some information on this I'd appreciate it.

THANKS!
 
// starting an executable:

STARTUPINFO si;
PROCESS_INFORMATION pi;
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWMINNOACTIVE;
CString exe = ...
CString dir = ....
CreateProcess( exe , NULL , NULL , NULL , FALSE , 0 , NULL , dir , &si , &pi );

// ending the executable:

TerminateProcess( pi.hProcess , 9 );

What you mean by "running it in your client window" ?
 
> What you mean by "running it in your client window" ?

The way I read Jouster's post he want's to host the application inside his applications window.

That would make the external application a 'component' of the host. Of course that is the purpose of COM and I believe the component (external) application would have to be a COM server to accomplish it.

-pete
 
Thank you both for your information. What I'm trying to do is run an animation file I have, self-contained in an exe file, for a specific amount of time then shutdown and continue with my program. I painted the screen Black for the backgound and created the process and the process shows up behind my painted screen. Thats why I thought I needed it to run inm y client window. I can create the process using the example above, but I cant shut it down. I've only scrathed the surface of COM and was trying to find an easier way of doing this.

Jouster
 
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.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top