FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour isexerunning (Solved)
Posts: 566
Joined: Thu Aug 30, 2007 03:40 PM
isexerunning (Solved)
Posted: Fri May 04, 2012 04:57 PM

HI, this code: (by EMG)

IF ISEXERUNNING( CFILENOEXT( HB_ARGV( 0 ) ) )
SHOWWINDOW( FINDWINDOW( 0, "Titolo tua finestra" ), 9 )
SETFOREGROUNDWINDOW( FINDWINDOW( 0, "Titolo tua finestra" ) )
RETURN NIL
ENDIF

works before build window of exe?

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: isexerunning
Posted: Fri May 04, 2012 05:59 PM

Norberto,

It requires the main window to exist already

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 566
Joined: Thu Aug 30, 2007 03:40 PM
Re: isexerunning
Posted: Fri May 04, 2012 06:09 PM

Antonio,

i need some method to before creation of the main window. I need detect it is already running and put the focus on open application.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: isexerunning
Posted: Fri May 04, 2012 06:27 PM
Norberto,

Try to use:
Code (fw): Select all Collapse
if GetModuleHandle( HB_ARGV( 0 ) ) != 0
   MsgInfo( "App already running" )
   return 0
endif
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 566
Joined: Thu Aug 30, 2007 03:40 PM
Re: isexerunning
Posted: Fri May 04, 2012 06:43 PM

Antonio, isexerunning works without main window, but i cant put focus in already open appl.

thanks

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: isexerunning
Posted: Fri May 04, 2012 07:23 PM

Norberto,

If there is no user input in the already running app, what do you mean/expect giving it the focus ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 566
Joined: Thu Aug 30, 2007 03:40 PM
Re: isexerunning
Posted: Fri May 04, 2012 07:39 PM

Antonio,

I need detect another instance of the same application, and if there is another instance, transfer focus to it, maybe showing the screen in the foreground, but I wanted to do this before the initial window, perhaps checking the name of the executable and not the window title.

thanks

Posts: 581
Joined: Tue Oct 11, 2005 11:28 AM
Re: isexerunning
Posted: Sat May 05, 2012 12:51 PM
Norberto,

Try it:

Code (fw): Select all Collapse
pTitulo:="Nome do teu sistema que fica na barra de cima da Window"
If IsExeRunning( cFilename( hb_Argv(0) ) ) 
   SHOWWINDOW( FINDWINDOW( 0, pTitulo ), 3 )
   SETFOREGROUNDWINDOW( FINDWINDOW( 0, pTitulo ) )
   return nil
Endif
Kleyber Derick



FWH / xHb / xDevStudio / SQLLIB
Posts: 566
Joined: Thu Aug 30, 2007 03:40 PM
Re: isexerunning
Posted: Sat May 05, 2012 01:16 PM

Kleyber, this works after build main window, i need before.
i need something using the name of exe, not main windows title, because at this point , it not create.

Thanks

Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: isexerunning
Posted: Sat May 05, 2012 08:18 PM
Norberto,
this is working for me.
Best regards,
Otto

Code (fw): Select all Collapse
FUNCTION main
    if IsExeRunning( cFileName( HB_ARGV( 0 ) ) )
      ShowApplication()
   else
   
        DEFINE WINDOW oWnd

  
    WritePProString( "Programm" , "RECHNUNG", oWnd:cTitle(), ".\ini\whLink.ini" )
     
        ACTIVATE WINDOW oWnd MAXIMIZED
   
   
   
   endif
   
   return
 //----------------------------------------------------------------------------//
   
   
   
function ShowApplication()
   local hWnd := 0
   local cFileNoExt := ""
    local uVar = GetPvProfString( "Programm", "RECHNUNG", "WINHOTEL",".\ini\whLink.ini" )
   
   hWnd := FindWnd( uVar ) 

   if hWnd != nil
        if IsIconic( hWnd )
            ShowWindow( hWnd, SW_RESTORE )
        endif
        SetFocus( hWnd )
        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
//----------------------------------------------------------------------------//
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: isexerunning
Posted: Sat May 05, 2012 10:59 PM

Can we see a little but complete sample showing your problem? I didn't understand it.

EMG

Posts: 566
Joined: Thu Aug 30, 2007 03:40 PM
Re: isexerunning
Posted: Sat May 05, 2012 11:21 PM

Enrico, Otto, thanks, but dont work to me.
I wanted check the existence of another instance the application before creating the main window, before checking the User, open files, etc.
all the solutions posted work after the main window created .I wanted first of all, at the beginning of the system.
May have to get the handle of the system and not the name (caption)
i wanted to check the existence of another instance, move the focus to it, and leave the second instance (quit).

but thanks to all.

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: isexerunning
Posted: Sun May 06, 2012 08:57 AM
My sample works before the main windows is created.

EMG
Posts: 581
Joined: Tue Oct 11, 2005 11:28 AM
Re: isexerunning
Posted: Sun May 06, 2012 02:05 PM
norberto wrote:Kleyber, this works after build main window, i need before.
i need something using the name of exe, not main windows title, because at this point , it not create.

Thanks


Norberto,

I would like to understand it better: If you have another instance of your program, how is this running in you computer? I think it means the ohter instance is working and if it is working it has already a main window. Or not?
Kleyber Derick



FWH / xHb / xDevStudio / SQLLIB
Posts: 566
Joined: Thu Aug 30, 2007 03:40 PM
Re: isexerunning
Posted: Sun May 06, 2012 03:11 PM

hI, isexerunning detects another instance, but i cant put this in foreground (focus).