Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
One Instance
Message
De
26/11/2004 10:21:17
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
26/11/2004 10:08:53
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Versions des environnements
Visual FoxPro:
VFP 7
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Divers
Thread ID:
00957965
Message ID:
00964921
Vues:
11
>>>Hi All,
>>>
>>>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.
>>>
>>>TIA
>>
>>
>>* Entr
>>if IsAppRunning(Application.ServerName) && or any unique string you want - ie: MyNiceApplication
>>*...
>>endif
>>
>>Function IsAppRunning
>>	Lparameters tcSemaphoreName
>>	Local hsem, lpszSemName
>>	#Define ERROR_ALREADY_EXISTS 183
>>	Declare Integer GetLastError In win32API
>>	Declare Integer CreateSemaphore In WIN32API ;
>>		string @ lpSemaphoreAttributes, ;
>>		LONG lInitialCount, ;
>>		LONG lMaximumCount, ;
>>		string @ lpName
>>	hsem = CreateSemaphore(0,0,1,tcSemaphoreName)
>>	Return (hsem # 0 And GetLastError() == ERROR_ALREADY_EXISTS)
>>
Cetin
>
>Hi Cetin,
>you have found a code that with the semaphore, active the application that has created it?
>
>
>IF hsem # 0 And GetLastError() == ERROR_ALREADY_EXISTS
>   * samaphore => ProcessId => WHANDLE => SetForegroundWindow(WHANDLE)
>ENDIF
>
>
>I wan't use FindWindow because it is mistaken.
>
>Thanks
>Fabio

Fabio,
It finds the application no matter if it has a visual representation or not (or even invoked from IDE for testing - IOW you uniquely mark an 'application' not the window hosting it).
Are you asking how to activate its window if any? If so I've to find my code that collects all processes and their related window handles but for that as I remember I needed to also create a FLL (VFP not supporting callback functions).
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform