Hola a todos
He observado que la aplicaci贸n, cuando le pongo el SET MULTIPLE OFF no funciona y abre tantas ventanas de la aplicaci贸n como clicks le des al acceso directo. 驴Hay alguna equivalencia en Harbour?
Saludos
Hola a todos
He observado que la aplicaci贸n, cuando le pongo el SET MULTIPLE OFF no funciona y abre tantas ventanas de la aplicaci贸n como clicks le des al acceso directo. 驴Hay alguna equivalencia en Harbour?
Saludos
Hola,
No s茅 si hay equivalencia para el SET MULTIPLE OFF
Una alternativa es crear un fichero cualquiera ( FCreate("Semaforo.Nul", FO_EXCLUSIVE) ) en exclusivo. El primer usuario / primera vez que entra pilla semaforo verde. Las siguientes pulsaciones no permitir谩 acceder. Si el programa saliera por error automaticamente desaparece el enlace con Semaforo.Nul
Salu2
Gracias, Antonio
Function IsExeRunning( tcName, lTerminate )
Local oLocator
Local oWMI
Local oProcesses
Local oProcess
Local lIsRunning
Local nRet := 0
Local aProcess := {}
DEFAULT lTerminate := .F.
oLocator := CREATEOBJECT( "WBEMScripting.SWBEMLocator" )
oWMI := oLocator:ConnectServer()
oWMI:Security_:ImpersonationLevel := 3
oProcesses := oWMI:ExecQuery([SELECT * FROM Win32_Process]) // WHERE Name = '] + tcName + ['])
lIsRunning := .F.
if oProcesses:Count > 0
For Each oProcess in oProcesses
if Upper( AllTrim( oProcess:Name ) ) == Upper( AllTrim( tcName ) )
hRet := oProcess:Handle
lIsRunning := .T.
if lTerminate
nRet := oProcess:Terminate( 0 )
if nRet = 0
hRet := -1 // 驴?
lIsRunning := .F.
endif
endif
endif
//AAdd( aProcess, { oProcess:Name, oProcess:Handle } )
Next
endif
//XBrowse( aProcess )
Return lIsRunningGracias, Antonio y Crist贸bal
Saludos
incluir libreria hbwin.lib
/*Mutex constant for application*/
#define MUTEX_NAME 聽 聽 聽 聽 "KDSOFT_MYAPP"
STATIC hMutex
PROCEDURE Main()
聽 聽//main code :-)
RETURN
INIT PROCEDURE Main_Init()
聽 聽hMutex := wapi_CreateMutex( NIL, NIL, MUTEX_NAME )
聽 聽IF !Empty( hMutex ) .AND. wapi_GetLastError() == 0
聽 聽 聽 //allow execution of application
聽 聽ELSE
聽 聽 聽 MsgAlert( "La aplicaci贸n ya esta en ejecuci贸n, seleccionela en la barra de tareas.", "Alerta" )
聽 聽 聽 MyQuit()
聽 聽ENDIF
RETURN
/*-------------------------------------------------------------------------------------------------*/
EXIT PROCEDURE Main_End()
聽 聽IF !Empty( hMutex )
聽 聽 聽 hMutex := NIL
聽 聽ENDIF
聽 聽MyQuit()
RETURN
FUNCTION MyQuit()
聽 聽PostQuitMessage( 0 )
聽 聽__Quit()
RETURN__cExe := cFileName( HB_ARGV( 0 ) )
IF IsExeRunning( __cExe ) 聽// Verifica que no Exista una Aplicacion ya Corriendo en la Computadora
聽 聽 MiMsgStop( {"1 No Puedes tener 2 Aplicaciones Abiertas..."}, "Alto!", , .T., 5, .F.)
聽 聽Cerrar1()
ENDIFJavier,
Muy buena soluci贸n! ![]()
gracias por compartirla!
SET MULTIPLE ON/OFF
is implemented in FWH2203 to be released in a few days.