Instances multiples exe FoxPro

Résolu
ThierryCAMBA Messages postés 2 Date d'inscription dimanche 28 septembre 2003 Statut Membre Dernière intervention 14 janvier 2005 - 14 janv. 2005 à 00:05
ThierryCAMBA Messages postés 2 Date d'inscription dimanche 28 septembre 2003 Statut Membre Dernière intervention 14 janvier 2005 - 14 janv. 2005 à 10:10
Quelqu'un a-t-il une solution pour éviter qu'un exe FoxPro ne soit lancé plusieurs fois sous Windows. Il est possible bien sûr de tester l'existance d'un fichier temporaire dans le répertoire de l'application et de le supprimer en sortant, mais j'aurais préféré une solution plus élégante (faisant appel au API Windows ? ou autre chose).

Merci à tous.... !

Thierry CAMBA

2 réponses

ThierryPerretier Messages postés 103 Date d'inscription mardi 5 octobre 2004 Statut Membre Dernière intervention 6 juillet 2006 1
14 janv. 2005 à 00:50
Bonjour,

Voici 2 solutions :

*****

oWMI= GetObject("winmgmts:")
IF oWMI.ExecQuery([Select * from Win32_Process where name ="APP.EXE"]).count>0
MessageBox("APP.EXE déjà lancé")
QUIT
ENDIF

******

IF NOT FirstInstance()
QUIT
ENDIF


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
#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
3
ThierryCAMBA Messages postés 2 Date d'inscription dimanche 28 septembre 2003 Statut Membre Dernière intervention 14 janvier 2005
14 janv. 2005 à 10:10
Merci beaucoup pour ces infos qui m'ont bien aidées..... !
Une petite précision tout de même : les fonctions RemoveProp et ShowWindow ne doivent pas être en majuscules mais comme indiquées précedemment. D'autre part (sous Windows98 et FoxPro6) il faut se passer du test IF Version(2).....

Sinon tout fonctionne.... !

Thierry CAMBA
0
Rejoignez-nous