Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How can I avoid to multiple run of VFP application on one PC
Message
From
26/05/2005 12:15:17
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
How can I avoid to multiple run of VFP application on one PC
Environment versions
Visual FoxPro:
VFP 7 SP1
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01017848
Message ID:
01017848
Views:
84
Could somebody tell me the way to avoid multiple running of one VFP application on
one machine at the same time. I have some tip to use CreateMutex(...), but it seems
doesn't work:
*!* APPClass.Init
LPARAMETERS pScreenTitle, pMutex
#DEFINE ERROR_ALREADY_EXISTS 255
DECLARE INTEGER CreateMutex	        IN win32api INTEGER, INTEGER, STRING @
DECLARE INTEGER CloseHandle	        IN win32api INTEGER
DECLARE INTEGER GetLastError        IN win32api
DECLARE INTEGER FindWindow          IN Win32api STRING, STRING
DECLARE INTEGER IsIconic            IN Win32api INTEGER
DECLARE         ShowWindow          IN Win32api INTEGER, INTEGER
DECLARE         SetForegroundWindow IN Win32api INTEGER

LOCAL lMutex, nWinHandle,lnError
lMutex = IIF(pcount()<2, pScreenTitle, pMutex)
THIS.nExeHwnd = CreateMutex(0, 1, @lMutex)
lnError=GetLastError()
IF lnError = ERROR_ALREADY_EXISTS
	CloseHandle(THIS.nExeHwnd)
	MESSAGEBOX("ERROR"+CHR(13)+"This application is allready running."+CHR(13)+ "Shut down...", ;
		MB_OK+MB_ICONSTOP, pScreenTitle)
		MB_OK+MB_ICONSTOP, pScreenTitle)
	nWinHandle = FindWindow(NULL, pScreenTitle)
	IF nWinHandle # 0
		IF IsIconic(nWinHandle) = 1
			ShowWindow(nWinHandle,4)
		ENDIF
		SetForegroundWindow(nWinHandle)
	ENDIF
	RETURN .F.
ENDIF
Thanks for your reactions.
Next
Reply
Map
View

Click here to load this message in the networking platform