C++ program to bring a process to foreground if already running otherwise create a new process

2k views Asked by At

I am trying to learn windows programming. I would like to launch an executable program.exe (say) from c++ code. I am able to achieve this by using CreateProcess() method in windows. However, my problem is if the process is already created and running in the background then the windows for program.exe should come to foreground otherwise a new process should be created and brought to the foreground. Any help will be appreciated.

2

There are 2 answers

0
Remy Lebeau On

Look at Win32 API functions such as the following:

1
Vlad Feinstein On

Is that program.exe written by you? This functionality is better handled there: on start you check if there is already an instance running and if there is - activate it. Otherwise - what do you do if there are multiple instances of program.exe already running?