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
IF ISEXERUNNING( CFILENOEXT( HB_ARGV( 0 ) ) )
SHOWWINDOW( FINDWINDOW( 0, cMainWindowCaption ), 9 )
SETFOREGROUNDWINDOW( FINDWINDOW( 0, cMainWindowCaption ) )
RETURN NIL
ENDIF
IF FINDWINDOW( 0, cMainWindowCaption ) > 0
SHOWWINDOW( FINDWINDOW( 0, cMainWindowCaption ), 9 )
SETFOREGROUNDWINDOW( FINDWINDOW( 0, cMainWindowCaption ) )
RETURN NIL
ENDIF
...
GLOBAL oMutex
...
...
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
...
//-----------------------------------------------------------------------------
#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
//-----------------------------------------------------------------------------
Enrico Maria Giordano wrote:Try (not tested):
- Code: Select all Expand view
IF FINDWINDOW( 0, cMainWindowCaption ) > 0
SHOWWINDOW( FINDWINDOW( 0, cMainWindowCaption ), 9 )
SETFOREGROUNDWINDOW( FINDWINDOW( 0, cMainWindowCaption ) )
RETURN NIL
ENDIF
EMG
fraxzi wrote:Enrico Maria Giordano wrote:Try (not tested):
- Code: Select all Expand view
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
#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
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: nageswaragunupudi and 106 guests