Starting another application within an application using start.pro

G

Guest

Hello, I am using VB.Net VS 2005. I have two Windows applications. The first
application has a command button with the following code that starts the 2nd
application.

Dim oStartInfo As ProcessStartInfo = New ProcessStartInfo
oStartInfo.FileName = "H:\RevTrak\RevTrak.exe"
Process.Start(oStartInfo)

This code works ok; however, there are two problems that I cannot resolve.

1. Each time the command button is clicked, another instance of the
executable program (RevTrak.exe) is started, which I do not want. I only want
one instance of the program to be running.

2. If the program is already running, I do not want to start another
instance of the program. I want the currently running program's window to get
focus (or to activate the window).

Thanks for your help.
 
P

Peter Duniho

[...]
1. Each time the command button is clicked, another instance of the
executable program (RevTrak.exe) is started, which I do not want. I only
want
one instance of the program to be running.

2. If the program is already running, I do not want to start another
instance of the program. I want the currently running program's window
to get
focus (or to activate the window).

I don't know the specific calls you need to make, but I can at least give
you some advice as to where to look and what you're trying to do.

Before you do the Process.Start() code, you need to search the top-level
window list or, preferably, the process list (so you can actually check
the executable name rather than the window name), to see if the
application you wanted started has already been started. If you don't
find the application, start the process as normal.

Otherwise, once you have found the window (either directly or via the
process), then you need to activate it. As long as your application is
already the foreground application, this should bring the other process to
the foreground. If not, you will likely just get a task bar notification
(flashing task bar item).

Pete
 
G

Guest

Thanks Pete. Once I determine the program is already running, how do I
activate the program (so it has focus)? Is there a WIN32 API function call
for this?

JDH


Peter Duniho said:
[...]
1. Each time the command button is clicked, another instance of the
executable program (RevTrak.exe) is started, which I do not want. I only
want
one instance of the program to be running.

2. If the program is already running, I do not want to start another
instance of the program. I want the currently running program's window
to get
focus (or to activate the window).

I don't know the specific calls you need to make, but I can at least give
you some advice as to where to look and what you're trying to do.

Before you do the Process.Start() code, you need to search the top-level
window list or, preferably, the process list (so you can actually check
the executable name rather than the window name), to see if the
application you wanted started has already been started. If you don't
find the application, start the process as normal.

Otherwise, once you have found the window (either directly or via the
process), then you need to activate it. As long as your application is
already the foreground application, this should bring the other process to
the foreground. If not, you will likely just get a task bar notification
(flashing task bar item).

Pete
 
P

Peter Duniho

Thanks Pete. Once I determine the program is already running, how do I
activate the program (so it has focus)? Is there a WIN32 API function
call for this?

Yes. I used to know the name of it off the top of my head, but can't
think of it right now. Probably something like ActivateWindow() or
something else along those lines.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top