FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour SetMultiple Not working..
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
SetMultiple Not working..
Posted: Mon Oct 18, 2010 06:49 AM

Dear All

When I set to Setmultiple( .F. )... the app can still be open/execute. How to avoid running same program at the same time?

I'm using FWH 10.6

Kind Regards,
Frances

Kind Regards,

Frances



Fivewin for xHarbour v18.07

xHarbour v1.2.3.x

BCC 7.3 + PellesC8 ( Resource Compiler only)

ADS 10.1 / MariaDB

Crystal Reports 8.5/9.23 DE

xMate v1.15
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: SetMultiple Not working..
Posted: Mon Oct 18, 2010 07:23 AM
Use this:

Code (fw): Select all Collapse
IF ISEXERUNNING( CFILENOEXT( HB_ARGV( 0 ) ) )
    SHOWWINDOW( FINDWINDOW( 0, cMainWindowCaption ), 9 )
    SETFOREGROUNDWINDOW( FINDWINDOW( 0, cMainWindowCaption ) )
    RETURN NIL
ENDIF


EMG
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: SetMultiple Not working..
Posted: Mon Oct 18, 2010 03:48 PM

Dear EMG,

It works.. but if you copy the .exe and run the copied .exe it will run again..
Is there a way to avoid running the copied .exe when the original .exe is currently running?

Kind regards,
Frances

Kind Regards,

Frances



Fivewin for xHarbour v18.07

xHarbour v1.2.3.x

BCC 7.3 + PellesC8 ( Resource Compiler only)

ADS 10.1 / MariaDB

Crystal Reports 8.5/9.23 DE

xMate v1.15
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: SetMultiple Not working..
Posted: Mon Oct 18, 2010 04:09 PM
Try (not tested):

Code (fw): Select all Collapse
IF FINDWINDOW( 0, cMainWindowCaption ) > 0
    SHOWWINDOW( FINDWINDOW( 0, cMainWindowCaption ), 9 )
    SETFOREGROUNDWINDOW( FINDWINDOW( 0, cMainWindowCaption ) )
    RETURN NIL
ENDIF


EMG
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: SetMultiple Not working..
Posted: Mon Oct 18, 2010 08:38 PM
I use this code in my app, i use xharbour, the GLOBAL is exclusive in xharbour, but you can use static with harbour.
the functions "main_ini" and "main_end" is calls automatic for xharbour. not is need call manually in the code.


sorry for my bad english.

salu2
carlos vargas


add this line al begin in your main prg.
Code (fw): Select all Collapse
...
GLOBAL oMutex
...


add this functions to main prg
Code (fw): Select all Collapse
...
INIT PROCEDURE Main_Ini()

   /*crea objeto tmutex*/
   oMutex := TMutex():Open( NIL, FALSE, "KDSoft" )

   /*valida mutex*/
   IF oMutex:hMutex==0
      oMutex := TMutex():Create( NIL, FALSE, "KDSoft" )
   ELSE
      MsgAlert("La aplicación esta en ejecución actualmente!")
      oMutex:Close()
      QUIT
   ENDIF

RETURN

/*Elimina mutex creado*/
EXIT PROCEDURE Main_End()

   IF oMutex != Nil
      oMutex:Close()
   ENDIF

RETURN

...




add tyhis file tmutex.prg to your project.
Code (fw): Select all Collapse
//-----------------------------------------------------------------------------

#include "FiveWin.ch"

//-----------------------------------------------------------------------------

#define iKERNEL         "Kernel32.dll"
#define iASPASCAL       .T.

#define iTRUE           1
#define iFALSE          0

#define MUTANT_QUERY_STATE            1
#define STANDARD_RIGHTS_REQUIRED      983040
#define SYNCHRONIZE                   1048576
#define MUTEX_ALL_ACCESS              nOr( STANDARD_RIGHTS_REQUIRED, SYNCHRONIZE, MUTANT_QUERY_STATE )

#xtranslate Bool2Int( <lVar> )  =>  If( <lVar>, iTRUE, iFALSE )

//-----------------------------------------------------------------------------

CREATE CLASS TMutex
   DATA cName
   DATA hMutex

   METHOD Create( sMutexAttr, lInitialOwner, cName ) CONSTRUCTOR
   METHOD New( sMutexAttr, lInitialOwner, cName ) INLINE ::Create( sMutexAttr, lInitialOwner, cName )
   METHOD Open( nAccess, lInitialOwner, cName ) Constructor
   METHOD Close()
   METHOD Release()
   METHOD End() INLINE ::Close()
   METHOD Failed() HIDDEN

ENDCLASS

//-----------------------------------------------------------------------------

METHOD Create( sMutexAttr, lInitialOwner, cName ) CLASS TMutex
   LOCAL hDLL    := LoadLibrary( iKERNEL )
   LOCAL cFunc   := "CreateMutexA"
   LOCAL cBuffer := NIL
   LOCAL cFarProc

   DEFAULT lInitialOwner := .F., cName := "FiveWin App"

   ::hMutex := 0
   ::cName  := ""

   IF ValType( sMutexAttr ) == "O" .and. Upper( sMutexAttr:className() ) == "TSTRUCT"
      cBuffer := sMutexAttr:cBuffer
   Endif

   ::cName := cName

   IF Abs( hDLL ) > 32
      cFarProc := GetProcAdd( hDLL, cFunc, iASPASCAL, LONG, LONG, LONG, STRING )
      ::hMutex := FWCallDLL( cFarProc,  iif( cBuffer != NIL, @cBuffer, cBuffer ), Bool2Int( lInitialOwner ), cName + Chr(0) )
      FreeLibrary( hDLL )
      IF cBuffer != NIL
         sMutexAttr:cBuffer := cBuffer
      ENDIF
   ELSE
      ::Failed( hDLL, cFunc )
   ENDIF

RETURN Self

//-----------------------------------------------------------------------------

METHOD Open( nAccess, lInitialOwner, cName ) CLASS TMutex
   LOCAL hDLL    := LoadLibrary( iKERNEL )
   LOCAL cFunc   := "OpenMutexA"
   LOCAL cFarProc

   DEFAULT nAccess := MUTEX_ALL_ACCESS, lInitialOwner := .F., cName := "FiveWin App"

   ::cName := cName

   IF Abs( hDLL ) > 32
      cFarProc := GetProcAdd( hDLL, cFunc, iASPASCAL, LONG, LONG, LONG, STRING )
      ::hMutex := FWCallDLL( cFarProc, nAccess, Bool2Int( lInitialOwner ), cName + Chr(0) )
      FreeLibrary( hDLL )
   ELSE
      ::Failed( hDLL, cFunc )
   ENDIF

RETURN Self

//-----------------------------------------------------------------------------

METHOD Close() CLASS TMutex
   LOCAL hDLL  := LoadLibrary( iKERNEL )
   LOCAL cFunc := "CloseHandle"
   LOCAL nResult
   LOCAL cFarProc

   IF Abs( hDLL ) > 32
      cFarProc := GetProcAdd( hDLL, cFunc, iASPASCAL, LONG, LONG )
      nResult  := FWCallDLL( cFarProc, ::hMutex )
      FreeLibrary( hDLL )
      ::hMutex := 0
   ELSE
      ::Failed( hDLL, cFunc )
   ENDIF

RETURN nResult

//-----------------------------------------------------------------------------

METHOD Release() CLASS TMutex
   LOCAL hDLL  := LoadLibrary( iKERNEL )
   LOCAL cFunc := "ReleaseMutex"
   LOCAL cFarProc
   LOCAL nResult

   IF Abs( hDLL ) > 32
      cFarProc := GetProcAdd( hDLL, cFunc, iASPASCAL, LONG, LONG )
      nResult := FWCallDLL( cFarProc, ::hMutex )
      FreeLibrary( hDLL )
   ELSE
      ::Failed( hDLL, cFunc )
   ENDIF

RETURN nResult

//-----------------------------------------------------------------------------

METHOD Failed( nError, cFunc ) CLASS TMutex
   MsgAlert( "Error: " + LTrim( Str( nError ) ) + " al cargar " + iKERNEL + CRLF + "Función: " + cFunc, "Clase " + ::className() )
RETURN Self


//-----------------------------------------------------------------------------
//EOF
//-----------------------------------------------------------------------------
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: SetMultiple Not working..
Posted: Tue Oct 19, 2010 12:00 AM
Enrico Maria Giordano wrote:Try (not tested):

Code (fw): Select all Collapse
IF FINDWINDOW( 0, cMainWindowCaption ) > 0
    SHOWWINDOW( FINDWINDOW( 0, cMainWindowCaption ), 9 )
    SETFOREGROUNDWINDOW( FINDWINDOW( 0, cMainWindowCaption ) )
    RETURN NIL
ENDIF


EMG



Dear EMG,

It didn't work...


Kind Regards,
Frances
Kind Regards,

Frances



Fivewin for xHarbour v18.07

xHarbour v1.2.3.x

BCC 7.3 + PellesC8 ( Resource Compiler only)

ADS 10.1 / MariaDB

Crystal Reports 8.5/9.23 DE

xMate v1.15
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: SetMultiple Not working..
Posted: Tue Oct 19, 2010 12:34 AM

Dear Mr. Carlos,

Your solution works.

I run and I copied the original .exe and run again the copied .exe and successfully detected another program of the same .exe is running.
It works in XP SP3 x86/Vista Ultimate x86/Win7 ultimate x86/Win2003 Server x86/WinServer Web 2008 R2 Ent x64

Can you explain more details?

Kind Regards,
Frances

Kind Regards,

Frances



Fivewin for xHarbour v18.07

xHarbour v1.2.3.x

BCC 7.3 + PellesC8 ( Resource Compiler only)

ADS 10.1 / MariaDB

Crystal Reports 8.5/9.23 DE

xMate v1.15
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: SetMultiple Not working..
Posted: Tue Oct 19, 2010 03:56 AM

Sorry, this code is work a another friend.
in this forums a found this code.

salu2
carlos vargas

Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: SetMultiple Not working..
Posted: Tue Oct 19, 2010 06:53 AM
fraxzi wrote:
Enrico Maria Giordano wrote:Try (not tested):

Code (fw): Select all Collapse
IF FINDWINDOW( 0, cMainWindowCaption ) > 0
    SHOWWINDOW( FINDWINDOW( 0, cMainWindowCaption ), 9 )
    SETFOREGROUNDWINDOW( FINDWINDOW( 0, cMainWindowCaption ) )
    RETURN NIL
ENDIF


EMG



Dear EMG,

It didn't work...


Kind Regards,
Frances


This is a working sample:

Code (fw): Select all Collapse
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oWnd

    LOCAL cTitle := "This is a test"

    IF FINDWINDOW( 0, cTitle ) > 0
        SHOWWINDOW( FINDWINDOW( 0, cTitle ), 9 )
        SETFOREGROUNDWINDOW( FINDWINDOW( 0, cTitle ) )
        RETURN NIL
    ENDIF

    DEFINE WINDOW oWnd;
           TITLE cTitle

    ACTIVATE WINDOW oWnd

    RETURN NIL


EMG

Continue the discussion