Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is the Application already running???
Message
From
24/12/1999 02:41:53
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00308264
Message ID:
00308361
Views:
41
Hi Jim.

>> How can you test to see if a paticular visual foxpro application is already running and block the program from starting another occurance? <<
*******************************************************************************
* Program....: OnceOnly.prg
* Compiler...: Visual FoxPro 06.00.8492.00 for Windows
* Abstract...: Checks for an existing instance of the current application window
* ...........: and, if found, activates the original and returns a flag.
*******************************************************************************
FUNCTION OnceOnly
LOCAL lnHWND, lcTitle, llRetVal

*** Set UP API Calls
Declare Integer FindWindow IN Win32Api AS FindApp String, String
Declare BringWindowToTop   IN Win32APi AS MakeTop Integer
Declare ShowWindow         IN Win32Api AS ShowWin Integer, Integer
    
*** Get the current Screen Caption
lcTitle = _Screen.Caption

*** Change it to avoid finding the current instance
_Screen.Caption = SYS(3)

*** Now locate another instance
lnHWND = FindApp( NULL, lcTitle )

*** And restore the original caption
_Screen.Caption = lcTitle

*** Check the results
IF lnHWND > 0
  *** We have found something!
  *** So make it uppermost and maximize it (ShowWin => 3)
  MakeTop( lnHWND )
  ShowWin( lnHWND, 3 )
  *** Set the Return Value
  llRetVal = .T.
ENDIF

*** Return Status for action
RETURN llRetVal
Call the function like so:
IF OnceOnly()
  QUIT
ENDIF
Marcia
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform