Hi Jim,
I use this way
In Main.prg:
Public hsem
hsem = 0
IF IsRunning("your_string")
MessageBox("The program is active.")
QUIT
ENDIF
When you close APP:
DECLARE CloseHandle IN WIN32API LONG hHandle
CloseHandle(hsem)
and the function
FUNCTION IsRunning(tcSemaphoreName)
LOCAL lpszSemName
#Define ERROR_ALREADY_EXISTS 183
Declare Integer GetLastError In win32API
Declare Integer CreateSemaphore In WIN32API ;
string @ lpSemaphoreAttributes, ;
LONG lInitialCount, ;
LONG lMaximumCount, ;
string @ lpName
hsem = CreateSemaphore(0,0,1,tcSemaphoreName)
RETURN (hsem # 0 .AND. GetLastError() == ERROR_ALREADY_EXISTS)
HTH
>How can you test if your VFP application is already running? I have been using a function called "OnceOnly" that goes out and checks if the Window titles running match the one you want to load and if it does, it stops the loading of the app and sets focus to the running app. This works most of the time, but now my client wants me to change the Window Title of the application with the name of the user after the title. The "OnceOnly" function now does not see the application as running and starts another one. Does anyone know of another way to restrict the same application from running more than once at a time?
_______________________________________________________________
Testing displays the presence, not the absence of bugs.
If a software application has to be designed, it has to be designed correctly!
_______________________________________________________________
Vladimir Zografski
Systems Analyst