don't open duplicates of an exe

don't open duplicates of an exe

Postby Silvio.Falconi » Wed May 19, 2021 8:58 am

not to open the same exe I have always done this way (it seems to me that the source is EMG)

Code: Select all  Expand view

# define NOME_PROGRAMMA_TITLE "Winbeach"

Function Main()
...
 IF ISEXERUNNING( CFILENAME( HB_ARGV( 0 ) ) )
       MsgWait(NOME_PROGRAMMA_TITLE+"  è già in esecuzione !","Attenzione")
        SHOWWINDOW( FINDWND( NOME_PROGRAMMA_TITLE ), 9 )
        SETFOREGROUNDWINDOW( FINDWND( NOME_PROGRAMMA_TITLE ) )
        RETURN NIL
     ENDIF

   WITH OBJECT oApp := TApplication():New()
      :Activate()
   END



the function


Code: Select all  Expand view
FUNCTION FINDWND( cTitle )

    LOCAL hWnd := GETWINDOW( GETDESKTOPWINDOW(), GW_CHILD )

    WHILE hWnd != 0
        IF UPPER( cTitle ) $ UPPER( GETWINDOWTEXT( hWnd ) )
            RETURN hWnd
        ENDIF

        hWnd = GETWINDOW( hWnd, GW_HWNDNEXT )
    ENDDO

    RETURN NIL



now a strange thing happens to me that is
before accessing the application I do enter the access login for the users of the system
Let's imagine that the user gets distracted and opens the exe again
then we would have this situation

Image

ie it displays me the message that the application is already running

but then it happens that it still opens the main window as if it were another section then we would have this situation

Image


how should i do to avoid making the main window appear?

because it's very strange because I active the Main window on TApplication and on method Activate() where is the dialog of check login

Code: Select all  Expand view
method Activate() class TApplication

IF ::CheckLogin()
    GetWinCoors( ::oWndMain, ::cInifile )
   * Get_Modules(::cInifile)

   ::oWndMain:bResized := {|| ResizeWndMain() }
   ::oWndMain:aMinMaxInfo := { nil, nil, ,, 1130,650, , }

   ACTIVATE WINDOW ::oWndMain ;
      VALID ::ExitFromX()
ENDIF



when I show the login and a user enters I go to load a series of parameters for that user,
for example access to programs that are activated from the menu or from the buttonbar if I used
on method Activate()

::oWndMain:bInit := { || IIF(::CheckLogin(),,::ExitFromSource()) }

it can run but then I have problems because the buttonbar and the menu are allready load without the paramters I want for that user
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7048
Joined: Thu Oct 18, 2012 7:17 pm

Re: don't open duplicates of an exe

Postby karinha » Wed May 19, 2021 12:23 pm

Code: Select all  Expand view

   IF ISEXERUNNING( CFILENAME( HB_ARGV( 0 ) ) )

      MsgInfo( "WinOrcam.exe Já Está Rodando Nesta Máquina","WinOrcam.exe")

      SHOWWINDOW( FINDWINDOW( 0, "WINORCAM" ), 9 )

      SETFOREGROUNDWINDOW( FINDWINDOW( 0, "WINORCAM" ) )

      LIBERA_TUDO()

      RETURN NIL

   ENDIF

//--Fecha o Programa Definitivamente
FUNCTION LIBERA_TUDO()

   PUBLIC aArray, aResolucaoAtual

// lFechaJan := .F.
// lFechaWin := .F.

   //? "Desligando o NumLock"  // ESTA EM NUM_CAPS.PRG/E AQUI MESMO.
// SETNUMLOCK( .F. )

   // MsgStop( AltTabEnable( 0, .T. ), "Habilitando   ALT+TAB e ALT+ESC - Windows NT, 2k" )
// AltTabEnable( 0, .T. ) // LIGA O ALT+TAB

   IF FILE( "WINORCAM.LOG" )
      DELETEFILE( "WINORCAM.LOG" )
   ENDIF

   IF FILE( "ENCERRA.wav" )

      SndPlaySound( "ENCERRA.wav", 0 )

   ENDIF

   RELEASE FONT oFont
   // DeleteObject( oFont )
   // DeleteObject( oBrush )

   DbCommitAll()
   DbUnLockAll()
   DbCloseAll()
   FreeResources()
   Release All
   SysRefresh()
   HB_GCALL( .T. )  // xHarbour
   // hb_gcAlloc()  // Harbour

   CLEAR MEMORY
   // hb_gcFree() // nao funciona com xHarbour?

   IF FILE( "checkres.txt" )
      FErase( "checkres.txt" )
   ENDIF

   CheckRes()

   PostQuitMessage( 0 )
   QUIT

RETURN NIL
 
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7804
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: don't open duplicates of an exe

Postby Silvio.Falconi » Wed May 19, 2021 2:34 pm

karinha wrote:
Code: Select all  Expand view

   IF ISEXERUNNING( CFILENAME( HB_ARGV( 0 ) ) )

      MsgInfo( "WinOrcam.exe Já Está Rodando Nesta Máquina","WinOrcam.exe")

      SHOWWINDOW( FINDWINDOW( 0, "WINORCAM" ), 9 )

      SETFOREGROUNDWINDOW( FINDWINDOW( 0, "WINORCAM" ) )

      LIBERA_TUDO()

      RETURN NIL

   ENDIF

//--Fecha o Programa Definitivamente
FUNCTION LIBERA_TUDO()

   PUBLIC aArray, aResolucaoAtual

// lFechaJan := .F.
// lFechaWin := .F.

   //? "Desligando o NumLock"  // ESTA EM NUM_CAPS.PRG/E AQUI MESMO.
// SETNUMLOCK( .F. )

   // MsgStop( AltTabEnable( 0, .T. ), "Habilitando   ALT+TAB e ALT+ESC - Windows NT, 2k" )
// AltTabEnable( 0, .T. ) // LIGA O ALT+TAB

   IF FILE( "WINORCAM.LOG" )
      DELETEFILE( "WINORCAM.LOG" )
   ENDIF

   IF FILE( "ENCERRA.wav" )

      SndPlaySound( "ENCERRA.wav", 0 )

   ENDIF

   RELEASE FONT oFont
   // DeleteObject( oFont )
   // DeleteObject( oBrush )

   DbCommitAll()
   DbUnLockAll()
   DbCloseAll()
   FreeResources()
   Release All
   SysRefresh()
   HB_GCALL( .T. )  // xHarbour
   // hb_gcAlloc()  // Harbour

   CLEAR MEMORY
   // hb_gcFree() // nao funciona com xHarbour?

   IF FILE( "checkres.txt" )
      FErase( "checkres.txt" )
   ENDIF

   CheckRes()

   PostQuitMessage( 0 )
   QUIT

RETURN NIL
 




NOT RUN it 's the same
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7048
Joined: Thu Oct 18, 2012 7:17 pm

Re: don't open duplicates of an exe

Postby karinha » Wed May 19, 2021 3:11 pm

It works perfectly. Show how you are doing. What is the NAME of your EXECUTABLE? I don't understand why nothing works for you.

https://i.imgur.com/Xd9rfEn.png

Image

Regards.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7804
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: don't open duplicates of an exe

Postby Silvio.Falconi » Wed May 19, 2021 3:23 pm

ok now load the same exe again and then look at the computer task manager
however I use Harbor and it doesn't work on mine
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7048
Joined: Thu Oct 18, 2012 7:17 pm

Re: don't open duplicates of an exe

Postby karinha » Thu May 20, 2021 2:14 pm

Test now:

Code: Select all  Expand view

// SAMPLES\SILVIO.PRG

#Include "FiveWin.ch"

#Define CLR_LGRAY      nRGB( 230, 230, 230 )
#Define CLR_LGREEN     nRGB( 190, 215, 190 )
#Define CLR_VERMELHO   nRGB( 255, 000, 000 ) //-> Vermelho Para a Letra
#Define CLR_AMARELO    nRgb( 255, 255, 000 ) //-> Amarelo Para o Fundo
#Define CLR_MENTA      nRGB( 221, 255, 238 ) //-> Cor de Menta
#Define CLR_HMENTA     nRGB( 000, 128, 000 ) //-> Cor de Menta Light uiiii
#Define CLR_SOFTYELLOW nRGB( 255, 251, 225 )
#Define NOME_APP   "SILVIO"  // SILVIO.EXE

REQUEST HB_LANG_ES
REQUEST HB_CODEPAGE_ESWIN

ANNOUNCE RDDSYS
REQUEST OrdKeyNo, OrdKeyCount, OrdCreate, OrdKeyGoto // Para ListBox
REQUEST DBFCDX, DBFFPT

MEMVAR oApp

/*_____________________________________________________________________________*/

FUNCTION Main()

   PUBLIC oApp

   rddSetDefault( "DBFCDX" )
   hb_langSelect( 'ES' )

   HB_SETCODEPAGE( 'ESWIN' )

   // SetHandleCount( 100 ) // FIVEWIN FOR CLIPPER

   /*
   SET DATE FORMAT "dd-mm-yyyy"
   SET DELETED     ON
   SET CENTURY     ON
   SET EPOCH TO    Year( Date() ) - 20
   SET MULTIPLE    OFF
   */


   SET CENTURY ON
   SET DATE BRITISH
   SET TIME FORMAT TO "HH:MM:SS"
   SET EPOCH TO YEAR( DATE() ) - 30
   SET SOFTSEEK OFF
   SET WRAP ON
   SETCANCEL( .F. )
   SET CONFIRM OFF
   SET DELETED ON
   SET _3DLOOK ON
   SET UNIQUE OFF
   SET ESCAPE OFF
   SET EXACT ON
   SET EXCLUSIVE OFF
   SET MULTIPLE OFF

   // CREAR UN ICONE EN EL DESKTOP PARA TESTE EN RED SILVIO.
   IF ISEXERUNNING( CFILENAME( HB_ARGV( 0 ) ) )

      // NOMBRE DEL EJECUTABLE Por ejemplo: SILVIO.EXE - ESCOLA.EXE
      MsgInfo( "SILVIO.exe Já Está Rodando Nesta Máquina","SILVIO.exe")

      SHOWWINDOW( FINDWINDOW( 0, "SILVIO" ), 9 )

      SETFOREGROUNDWINDOW( FINDWINDOW( 0, "SILVIO" ) )

      DbCommitAll()
      DbUnLockAll()
      DbCloseAll()
      FreeResources()
      Release All
      SysRefresh()
      HB_GCALL( .T. )  // xHarbour
      // hb_gcAlloc()  // Harbour

      CLEAR MEMORY
      // hb_gcFree() // nao funciona com xHarbour.

      PostQuitMessage( 0 )
      QUIT

      RETURN NIL

   ENDIF

   SetDialogEsc( .F. )  // DESLIGA O ESC NO DIALOGO
   SetBalloon( .T. )    // Balloon shape required for tooltips
   SkinButtons()        // Botoes Coloridos nas novas versoes

   SetGetColorFocus( CLR_BLACK )

   tGet():lDisColors  := .F.
   tGet():nClrTextDis := CLR_HBLUE
   tGet():nClrPaneDis := CLR_SOFTYELLOW

   WITH OBJECT oApp := TApplication():New()
      :Activate()
   END

RETURN NIL

/*_____________________________________________________________________________*/

CLASS tApplication

   DATA cAppName
   DATA cVersion
   DATA cEdicion
   DATA cBuild
   DATA cUrl
   DATA cMsgBar
   DATA cIniFile
   DATA cZipPath
   DATA oWndMain
   DATA oFont
   DATA oBar
   DATA oExit
   DATA oIcon
   DATA oMsgItem1
   DATA oMsgItem2
   DATA oMsgItem3
   DATA oDlg
   DATA oGrid
   DATA oTab
   DATA oSplit
   DATA nEdit
   DATA cLanguage

   METHOD New() CONSTRUCTOR

   METHOD Activate()

   METHOD BuildMenu()

   METHOD BuildBtnBar()

   METHOD Close()

   METHOD End() INLINE ( SetWinCoors( ::oWndMain, ::cIniFile ), ::oWndMain:End() )

   METHOD ExitFromX()

   METHOD ExitFromBtn()

   METHOD ExitFromSource()

   METHOD checklogin()

ENDCLASS

/*_____________________________________________________________________________*/

METHOD New() CLASS tApplication

   ::cAppName  := NOME_APP
   ::cVersion  := "1.001"
   ::cBuild    := "build "
   ::cUrl      := "http://www.google.com"
   ::cMsgBar   := "©  software"
   ::cIniFile  := cFilePath( GetModuleFileName( GetInstance() ) ) + "TEST.ini"
   ::cLanguage := "ES"
   ::oDlg      := nil
   ::nEdit     := 0
   ::oFont = TFont():New( GetDefaultFontName(), 0, GetDefaultFontHeight(),, )

   DEFINE ICON ::oIcon RESOURCE "ICON1"

   DEFINE WINDOW ::oWndMain   ;
      TITLE ::cAppName + ::cVersion ;
      MENU ::BuildMenu()      ;
      COLOR CLR_BLACK, GetSysColor( 15 ) - Rgb( 30, 30, 30 ) ;
      ICON ::oIcon

   SET MESSAGE OF ::oWndMain TO ::cMsgBar CENTER NOINSET

   DEFINE MSGITEM ::oMsgItem2;
      OF ::oWndMain:oMsgBar ;
      PROMPT ::cMsgBar      ;
      SIZE 100              ;
      BITMAPS "MSG_LOTUS", "MSG_LOTUS";
      TOOLTIP " " + i18n( "Acerca de..." ) + " ";
      ACTION MsgInfo( "Test de Full Single Document Interface" )

   DEFINE MSGITEM ::oMsgItem3 OF ::oWndMain:oMsgBar ;
      SIZE 132 ;
      TOOLTIP i18n( "test" ) ;
      PROMPT "www.google.com" ;
      COLOR CLR_HBLUE, GetSysColor( 15 )    ;
      ACTION nil

   ::oWndMain:oMsgBar:DateOn()

   ::BuildBtnBar()

RETURN Self

/*_____________________________________________________________________________*/

METHOD Activate() CLASS TApplication

   IF !::checklogin()

   ELSE

      GetWinCoors( ::oWndMain, ::cInifile )

      ::oWndMain:bResized := {|| ResizeWndMain() }

      ACTIVATE WINDOW ::oWndMain ;
         VALID ::ExitFromX()

      ::oFont:End()

   ENDIF

RETURN NIL

/*_____________________________________________________________________________*/

METHOD BuildMenu() CLASS TApplication

   LOCAL oMenu

   MENU oMenu

      MENUITEM "&Archivo"

      MENU

      MENUITEM i18n( "Especificar impresora" ) ;
         ACTION PrinterSetup() ;
         MESSAGE i18n( " Establecer la Configuración de su impresora. " )

      SEPARATOR
      MENUITEM i18n( "Salir" ) ;
         ACTION ::ExitFromBtn() ;
         MESSAGE i18n( " Terminar la ejecución del programa. " )

      ENDMENU

   ENDMENU

RETURN( oMenu )

/*_____________________________________________________________________________*/

METHOD BuildBtnBar() CLASS TApplication

   LOCAL oBtnTbl

   DEFINE BUTTONBAR ::oBar _3D SIZE 44, 46 OF ::oWndMain // 36, 40

   ::oBar:bRClicked := {|| .T. }

   DEFINE BUTTON OF ::oBar ;
      RESOURCE "BB1"       ;
      TOOLTIP i18n( "Gestión de documentos" ) ;
      MESSAGE i18n( "Gestión de del fichero de documentos." ) ;
      ACTION NIL   ;
      NOBORDER

   DEFINE BUTTON OF ::oBar ;
      RESOURCE "BB1"       ;
      TOOLTIP i18n( "Gestión de documentos" ) ;
      MESSAGE i18n( "Gestión de del fichero de documentos." ) ;
      ACTION NIL   ;
      NOBORDER

   DEFINE BUTTON ::oExit OF ::oBar  ;
      RESOURCE "BB2"      ;
      TOOLTIP i18n( "Salir del programa" ) ;
      MESSAGE i18n( "Finalizar el uso del programa." ) ;
      ACTION ( ::ExitFromBtn() ) ;
      GROUP NOBORDER

RETURN Self

/*_____________________________________________________________________________*/


METHOD Close() CLASS TApplication

   // ResAllFree()

   RETURN NIL

/*_____________________________________________________________________________*/


METHOD ExitFromBtn() CLASS tApplication

   ::oWndMain:End()

   RETURN NIL

/*_____________________________________________________________________________*/

METHOD ExitFromX() CLASS tApplication

   IF oApp:oDlg != nil
      IF oApp:nEdit > 0
         msgStop( i18n( "No puede salir del programa hasta que no cierre las ventanas abiertas sobre el mantenimiento que está manejando." ) )
         RETURN .F.
      END

   END
   IF msgYesNo( i18n( "¿Desea finalizar el programa?" ) )
      IF oApp:oDlg != nil
         oApp:oDlg:End()
      ENDIF
      SetWinCoors( ::oWndMain, ::cIniFile )
      RETURN .T.
   END

RETURN( .F. )

/*_____________________________________________________________________________*/

METHOD ExitFromSource() CLASS tApplication

   ::oWndMain:bValid := {|| SetWinCoors( ::oWndMain, ::cIniFile ), .T. }
   ::oWndMain:End()

   RETURN NIL

FUNCTION oApp()

RETURN( oApp )

/*_____________________________________________________________________________*/

// ___ manejo de fuentes © Paco García 2006 ____________________________________//

#pragma BEGINDUMP
#include "Windows.h"
#include "hbapi.h"

HB_FUNC( GETDEFAULTFONTNAME )
{
   LOGFONT lf;
   GetObject( ( HFONT ) GetStockObject( DEFAULT_GUI_FONT )  , sizeof( LOGFONT ), &lf );
   hb_retc( lf.lfFaceName );
}

HB_FUNC( GETDEFAULTFONTHEIGHT )
{
   LOGFONT lf;
   GetObject( ( HFONT ) GetStockObject( DEFAULT_GUI_FONT )  , sizeof( LOGFONT ), &lf );
   hb_retni( lf.lfHeight );
}

HB_FUNC( GETDEFAULTFONTWIDTH )
{
   LOGFONT lf;
   GetObject( ( HFONT ) GetStockObject( DEFAULT_GUI_FONT )  , sizeof( LOGFONT ), &lf );
   hb_retni( lf.lfWidth );
}

HB_FUNC( GETDEFAULTFONTITALIC )
{
   LOGFONT lf;
   GetObject( ( HFONT ) GetStockObject( DEFAULT_GUI_FONT )  , sizeof( LOGFONT ), &lf );
   hb_retl( (BOOL) lf.lfItalic );
}

HB_FUNC( GETDEFAULTFONTUNDERLINE )
{
   LOGFONT lf;
   GetObject( ( HFONT ) GetStockObject( DEFAULT_GUI_FONT )  , sizeof( LOGFONT ), &lf );
   hb_retl( (BOOL) lf.lfUnderline );
}

HB_FUNC( GETDEFAULTFONTBOLD )
{
   LOGFONT lf;
   GetObject( ( HFONT ) GetStockObject( DEFAULT_GUI_FONT )  , sizeof( LOGFONT ), &lf );
   hb_retl( (BOOL) ( lf.lfWeight == 700 ) );
}

HB_FUNC( GETDEFAULTFONTSTRIKEOUT )
{
      LOGFONT lf;
      GetObject( ( HFONT ) GetStockObject( DEFAULT_GUI_FONT )  , sizeof( LOGFONT ), &lf );
      hb_retl( (BOOL) lf.lfStrikeOut );
}

#pragma ENDDUMP

// _____________________________________________________________________________//

FUNCTION ResizeWndMain()

   LOCAL aClient

   IF oApp():oDlg != NIL

      aClient := GetClientRect ( oApp():oWndMain:hWnd )

      oApp():oDlg:SetSize( aClient[ 4 ], aClient[ 3 ] - oApp():oWndMain:oBar:nHeight - oApp():oWndMain:oMsgBar:nHeight )
      oApp():oDlg:Refresh()
      oApp():oSplit:nLong := oApp():oDlg:nHeight // aClient[4]
      oApp():oSplit:Refresh()
      oApp():oGrid:SetSize( aClient[ 4 ] - oApp():oGrid:nLeft, oApp():oDlg:nHeight - 26 )
      oApp():oGrid:Refresh()
      oApp():oTab:nTop := oApp():oDlg:nHeight - 26
      oApp():oTab:Refresh()
      oApp():oWndMain:oMsgBar:Refresh()

   ENDIF

RETURN NIL

FUNCTION SetWinCoors();RETURN NIL

FUNCTION GetWinCoors();RETURN NIL

METHOD CHECKLOGIN() CLASS tApplication

   LOCAL oDlg, oGet
   LOCAL cCad := "Password... "
   LOCAL nNum := 0
   LOCAL dDat := Date()

   SET _3DLOOK ON

   DEFINE DIALOG oDlg TITLE "Login de Silvio with: -> " + FWDESCRIPTION

   oDlg:lHelpIcon := .F.

   @ 1,    2 SAY "Password:" OF oDlg

   @ 1,    6 GET oGet VAR cCad OF oDlg SIZE 60, 10 COLOR "W/G" PICTURE "@K"

   @ 1.8,  2 SAY "Number:" OF oDlg

   @ 2,    6 GET oGet VAR nNum OF oDlg SIZE 60, 10 PICTURE "9999999.99"

   @ 2.6,  2 SAY "Date:" OF oDlg

   @ 3,    6 GET oGet VAR dDat PICTURE "@D 99/99/9999" OF oDlg SIZE 40, 10   ;
      SPINNER

   @ 3,    7 BUTTON "&Ok" OF oDlg SIZE 30, 12 ACTION( oDlg:End() )

   @ 3,   16 BUTTON "&Cancel" SIZE 30, 12 OF oDlg                            ;
      ACTION( oDlg:End(), __QUIT() ) CANCEL
   
   ACTIVATE DIALOG oDlg CENTERED

RETURN( .T. )

// FIN / END - kapiabafwh@gmail.com - Joao Santos - Sao Paulo - Brazil.
 


Regards.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7804
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: don't open duplicates of an exe

Postby James Bott » Thu May 20, 2021 4:04 pm

Silvio,

This is from my note file:

--------------------------------------------------------------------------------
Posted: Sun Sep 17, 2006 11:56 pm
Post subject: Preventing more than one instance of an app running.
Author: Antonio Linares
--------------------------------------------------------------------------------

Otto,
Code:

Code: Select all  Expand view
#include "FiveWin.ch"

#define GW_CHILD      5
#define GW_HWNDNEXT   2

function Main()

   local oWnd
   
   if Is Exe Running( cFileName( HB_ARGV( 0 ) ) )
      ShowApplication()
   else    
      DEFINE WINDOW oWnd TITLE "Test"
   
      ACTIVATE WINDOW oWnd
   endif    
   
return nil    

function ShowApplication()

   local hWnd := FindWnd( cFileNoExt( HB_ARGV( 0 ) ) )
   
   if hWnd != nil
      SetForeGroundWindow( hWnd )
   endif    
   
return nil    

function FindWnd( cTitle )

   local hWnd := GetWindow( GetDesktopWindow(), GW_CHILD )

   while hWnd != 0
      if Upper( cTitle ) $ Upper( GetWindowText( hWnd ) )
         return hWnd
      endif

      hWnd = GetWindow( hWnd, GW_HWNDNEXT )
   end

return nil
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: don't open duplicates of an exe

Postby Silvio.Falconi » Thu May 20, 2021 4:20 pm

James
it seem run good
only where I must call the message "another copy allready run "
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7048
Joined: Thu Oct 18, 2012 7:17 pm

Re: don't open duplicates of an exe

Postby Silvio.Falconi » Thu May 20, 2021 4:31 pm

James,Santos,Otto

this run ok
Code: Select all  Expand view
#include "FiveWin.ch"

    #define GW_CHILD      5
    #define GW_HWNDNEXT   2


#include "FiveWin.ch"

REQUEST DBFCDX
REQUEST DBFFPT

REQUEST HB_LANG_ES
REQUEST HB_CODEPAGE_ESWIN


#DEFINE NOME_PROGRAMMA_TITLE "antonio"

memvar oApp

FUNCTION Main()

   PUBLIC oApp

   RddSetDefault( "DBFCDX" )
   HB_LANGSELECT( 'ES' )
   HB_SETCODEPAGE( 'ESWIN' )
   SetHandleCount( 100 )

   SET DATE FORMAT "dd-mm-yyyy"
   SET DELETED     ON
   SET CENTURY     ON
   SET EPOCH TO    year( date() ) - 20
   SET MULTIPLE    OFF


      IF IsExeRunning( cFileName( HB_ARGV( 0 ) ) )
           MsgWait(NOME_PROGRAMMA_TITLE+"  è già in esecuzione !","Attenzione")
          ShowApplication()
       ELSE
          WITH OBJECT oApp := TApplication():New()
             :Activate()
          END
        ENDIF
RETURN nil
//-----------------------------------------------------------------------------------------//
    function ShowApplication()
       local hWnd := FindWnd( cFileNoExt( HB_ARGV( 0 ) ) )
       if hWnd != nil
          SetForeGroundWindow( hWnd )
       endif
    return nil
//-----------------------------------------------------------------------------//
    function FindWnd( cTitle )
       local hWnd := GetWindow( GetDesktopWindow(), GW_CHILD )
       while hWnd != 0
          if Upper( cTitle ) $ Upper( GetWindowText( hWnd ) )
             return hWnd
          endif
          hWnd = GetWindow( hWnd, GW_HWNDNEXT )
       end
    return nil
//--------------------------------------------------------------------------------------------------//
 



Only if I have the exe "antonio.exe" iconized the procedure not search the exe and it doesn't show it on the desktop, how I can resolve it ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7048
Joined: Thu Oct 18, 2012 7:17 pm

Re: don't open duplicates of an exe

Postby karinha » Thu May 20, 2021 4:41 pm

Silvio escrebió:

Code: Select all  Expand view

" ahora tengo otro problema que tengo que solucionar, cuando un usuario ingresa inicia sesión y podemos bloquear la duplicación del exe en una computadora.  

Pero si ese mismo usuario cambia de computadora y entra al sistema con la misma cuenta,

¿cómo puedo bloquearlo?  

porque en efecto el usuario tendría dos computadoras funcionando con la misma cuenta"

 


Este usuário tiene um código de registro en un banco de datos, Silvio? Puedes, bloquear el código del usuário se el código de la computadora no és el mismo.

Solo un aidea...

Saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7804
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: don't open duplicates of an exe

Postby TimStone » Thu May 20, 2021 8:53 pm

I have used the following for many years:

Code: Select all  Expand view
IF IsExeRunning( CFILENOEXT( hb_argv( 0 ) ) )
      SHOWWINDOW( FINDWINDOW( 0, "Auto Shop Writer 11" ), 9 )
      SETFOREGROUNDWINDOW( FINDWINDOW( 0, "Auto Shop Writer 11" ) )
  ELSE
 


It works perfectly. Certainly you could put a popup in there with your message if desired.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: don't open duplicates of an exe

Postby James Bott » Thu May 20, 2021 11:26 pm

Certainly you could put a popup in there with your message if desired.


IMHO I would not. People don't want to be told they did something wrong by a computer. If at all possible, software should just fix the problem and be quiet about it.

Thanks for the code Tim. I have a routine, but it is 16 lines long. Short is better.
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 105 guests