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.
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_
1. Declare Global External Function
Function LONG FindWindowA(string lpClassName, string lpWindowName) library "user32.dll"
2.
In the application Open event use the following code:
IF FindWindowA(lsNull,"xxx" > 0 THEN
MessageBox("Application Error!",&
"Application is Already Running!",&
StopSign!,OK!)
Halt
END IF
Where you see "xxx" 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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.