|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
How to close a another program within C++
I'm using the system call to run a program within my code but I want to be able to close that program after a few seconds. What happens is I call the prgram and it runs and takes over my screen but it's waiting for the user to hit the ESC key to exit the program so if I don't hit exit...it'll stay on that program screen and won't return control to my program. What I was wondering if there is a way to kill that program after it runs for a while.
I'm creating a console project and I used this to call the other program system("C:\\program.exe"); |
|
#2
|
||||
|
||||
|
If you have the handle to the program, you can try sending it a WM_QUIT message using SendMessage(). If you're executing the program using system, instead of CreateProcess, then you can attempt to get the program's handle by using FindWindow() (assuming you know the title of the window or its window class).
Hope this helps! |
|
#3
|
||||
|
||||
|
You can also use TerminateProcess!
But this is very unusual. If you really want to "Shoot down" the program use it. With the SendMessage program will behave as if user clicked x-icon. WIth TerminateProcess it ends immediatly |
|
#4
|
|||
|
|||
|
TerminateProcess() would shutdown the program quite unclean. eg. it leave dlls open in memory. Avoid it if you can. But for a hanging program, it is often the only way.
__________________
-- Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > How to close a another program within C++ |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|