Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
One Instance
Message
From
04/11/2004 07:11:02
 
 
To
04/11/2004 00:51:36
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Environment versions
Visual FoxPro:
VFP 7
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
00957965
Message ID:
00958022
Views:
17
How would I write code(s) to allow only one instance of the application to be executed? (check and prevent execution) Any suggestions or ideas is very appreciated.

If you know the exact window caption of your application (that is, it does not change as the application runs), call this function from your main .prg and if it return .T., quit.
FUNCTION IsAppRunning
LOCAL lnHWND, lcTitle, llRetVal

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

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

*** Now locate another instance
lnHWND = FindWindow( 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)
  BringWindowToTop( lnHWND )
  ShowWindow( lnHWND, 3 )
  *** Set the Return Value
  llRetVal = .T.
ENDIF

*** Return Status for action
RETURN llRetVal
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform