Page 1 of 1

SET MULTIPLE EN HARBOUR

PostPosted: Tue Apr 05, 2022 7:30 am
by Ramón J.
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

Re: SET MULTIPLE EN HARBOUR

PostPosted: Tue Apr 05, 2022 7:43 am
by hmpaquito
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

Re: SET MULTIPLE EN HARBOUR

PostPosted: Tue Apr 05, 2022 9:13 am
by Antonio Linares
Ramón,

Efectivamente parece que no funciona SET MULTIPLE OFF en FWH 32/64 bits

Vamos a revisar si este código nos permite implementarlo:
https://stackoverflow.com/questions/20874381/get-a-process-id-in-c-by-name

Re: SET MULTIPLE EN HARBOUR

PostPosted: Tue Apr 05, 2022 9:39 am
by Ramón J.
Gracias, Antonio

Re: SET MULTIPLE EN HARBOUR

PostPosted: Tue Apr 05, 2022 10:21 am
by Antonio Linares
Gracias a Cristobal que nos ha compartido esta función que nos sirve para controlar el SET MULTIPLE OFF

Code: Select all  Expand view
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 lIsRunning

Re: SET MULTIPLE EN HARBOUR

PostPosted: Tue Apr 05, 2022 6:25 pm
by Ramón J.
Gracias, Antonio y Cristóbal

Saludos

Re: SET MULTIPLE EN HARBOUR

PostPosted: Tue Apr 05, 2022 9:31 pm
by carlos vargas
incluir libreria hbwin.lib

Code: Select all  Expand view

/*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


 

Re: SET MULTIPLE EN HARBOUR

PostPosted: Thu Apr 07, 2022 4:26 pm
by VitalJavier
Alguien me paso esto y funciono : (para no tener mas de 1 corriendo)
xHarbour

Code: Select all  Expand view

__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()
ENDIF          
 

Re: SET MULTIPLE EN HARBOUR

PostPosted: Fri Apr 08, 2022 11:18 am
by Antonio Linares
Javier,

Muy buena solución! :-)

gracias por compartirla!

Re: SET MULTIPLE EN HARBOUR

PostPosted: Sat Apr 09, 2022 2:24 pm
by nageswaragunupudi
SET MULTIPLE ON/OFF
is implemented in FWH2203 to be released in a few days.