Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
FirstInstance No Longer Working
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01308693
Message ID:
01308694
Vues:
16
Maybe _screen.caption is the same for both programs at that point?

>
>We have been using the FIRSTINSTANCE function for years to keep 2 of our programs from starting up more than ONCE per PC per login session. If the program starts, and sees that it is already running, it brings the running instance to the front of all programs, then exits the startup.
>
>Well, it used to work.
>
>Now, when you have progam A running, and you start up the other program B that uses the same FIRSTINSTANCE code, program B brings program A to the front, and then program B exits.
>
>And, it you have program B running, and you start up the other program A that uses the same FIRSTINSTANCE code, program A brings program B to the front, and then program A exits.
>
>Weird.
>
>Here is the calling code, the FIRSTINSTANCE code.
>
>Calling code
>
>*** Check to see if another Visual Pharmacy is running ***
>IF !FirstInstance()
>	CLOSE ALL
>	QUIT
>	RETURN .F.
>ENDIF
>
>
>and FIRSTINSTANCE
>
>FUNCTION FirstInstance
>	DECLARE INTEGER CreateMutex IN WIN32API INTEGER, INTEGER, STRING @
>	DECLARE INTEGER CloseHandle IN WIN32API INTEGER
>	DECLARE INTEGER GetLastError IN WIN32API
>	DECLARE INTEGER SetProp IN WIN32API INTEGER, STRING @, INTEGER
>	DECLARE INTEGER GetProp IN WIN32API INTEGER, STRING @
>	DECLARE INTEGER RemoveProp IN WIN32API INTEGER, STRING @
>	DECLARE INTEGER IsIconic IN WIN32API INTEGER
>	DECLARE INTEGER SetForegroundWindow IN WIN32API INTEGER
>	DECLARE INTEGER GetWindow IN WIN32API INTEGER, INTEGER
>	DECLARE INTEGER ShowWindow IN WIN32API INTEGER, INTEGER
>	DECLARE INTEGER GetDesktopWindow IN WIN32API
>	DECLARE LONG FindWindow IN WIN32API LONG, STRING
>	DECLARE Sleep IN Win32API INTEGER dwMilliseconds
>
>	#DEFINE SW_RESTORE               9
>	#DEFINE ERROR_ALREADY_EXISTS   183
>	#DEFINE GW_HWNDNEXT              2
>	#DEFINE GW_CHILD                 5
>	LOCAL llRetVal, lcExeFlag, lnExeHwnd, lnHwnd
>	IF VERSION(2) = 0
>		lcExeFlag = STRTRAN(_screen.caption, " ", "") + CHR(0)
>		lnExeHwnd = CreateMutex(0, 1, @lcExeFlag)
>		IF GetLastError() = ERROR_ALREADY_EXISTS
>			lnHwnd = GetWindow(GetDesktopWindow(), GW_CHILD)
>			DO WHILE lnHwnd > 0
>				IF GetProp(lnHwnd, @lcExeFlag) = 1
>					IF IsIconic(lnHwnd) > 0
>						ShowWindow(lnHwnd,SW_RESTORE)
>					ENDIF
>					SetForegroundWindow(lnHwnd)
>					EXIT
>				ENDIF
>				lnHwnd = GetWindow(lnHwnd,GW_HWNDNEXT)
>			ENDDO
>			CloseHandle(lnExeHwnd)
>			llRetVal = .F.
>		ELSE
>			SetProp(FindWindow(0, _screen.caption), @lcExeFlag, 1)
>			llRetVal = .T.
>		ENDIF
>	ELSE
>		llRetVal = .T.
>	ENDIF
>	RETURN llRetval
>ENDFUNC
>
>
>and remember, this code IS the SAME in both program A and B.
>
>Also, it does this on MY PC and another programmer here. BUT, on another programmer's PC, it works fine.
>
>Something on the PC's not the same anymore? A MS update changed the API's ???
>
>Thanks!
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform