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!

Application Launch 2

Status
Not open for further replies.

xtharmon

Programmer
Jan 23, 2003
6
US
When launching an application, how do I check to see if it is already running?
 
This is what we use:

ll_handle = Handle(GetApplication(),TRUE)

// If there is a previous copy of the EXE running.
IF ll_handle <> 0 THEN

// do whatever

END IF
 
...hm I think user was looking for more of a &quot;click-able&quot; solution :)
BTW: I am next in line for the answer
thanx_

> need more info?
:: don't click HERE ::
 
I also think he was looking for something that actually works.

The code given above will determine if the code is running from within powerbuilder (running man), or is running as an EXE file. It does not however tell you that you are the 2nd copy of 'my appname' that is opening.

Here is a couple of hits from a google search:

The solution I use most often uses DDE instead of the WINapi. You try and open a conversation with an app with your name, if you error, they you continue opening and setup your self up as a DDE server. If you can connect you are the 2nd instance and you exit. (you can also use the DDE connection you just made to bring the previous copy to the top and/or maxmize it).

I don't like the mutex solution since a failure in the PB App will not clear the mutex, and give a false negative.
 
thanx rawhide 58!
I am compleatly new to this...although I had Sybase since v 7...never bothered to use it before :)...I will look throught the links...
thanx_

> need more info?
:: don't click HERE ::
 
Here's how I have done it:

1. Declare Global External Function
Function LONG FindWindowA(string lpClassName, string lpWindowName) library &quot;user32.dll&quot;

2.
In the application Open event use the following code:

IF FindWindowA(lsNull,&quot;xxx&quot;) > 0 THEN
MessageBox(&quot;Application Error!&quot;,&
&quot;Application is Already Running!&quot;,&
StopSign!,OK!)
Halt
END IF

Where you see &quot;xxx&quot; in the FindWindow, substitute the EXACT contents of the title of your application's main window. This will be case-sensitive.

The result will be that when the app attempts to start, the message box will display and when OK is clicked the app instance that is trying to start will stop.

Of course, you may not find it appropriate to kill the app at application open. You may need to do some housekeeping first. This approach should work on all Win 32 bit systems.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top