FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How prevent running an application twice ?
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
How prevent running an application twice ?
Posted: Wed Feb 21, 2007 01:00 AM

Hello,

A FW16 application can't be run twice on a PC, unless it is run in different parts of the memories (properties of shortcut).

How can I prevent that a FW32 application is run twice ?

Thanks.

Michel

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 4
Joined: Wed Nov 29, 2006 11:23 PM
How prevent running an application twice ?
Posted: Wed Feb 21, 2007 04:12 AM

there is a tmutex class from fivewin.info (Patrick Mast) you should look at

Richard Grayden

Sydney,

NSW Australia
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
How prevent running an application twice ?
Posted: Wed Feb 21, 2007 07:53 AM
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
How prevent running an application twice ?
Posted: Wed Feb 21, 2007 08:37 AM
Antonio Linares wrote:
if Is Exe Running( cFileName( HB_ARGV( 0 ) ) )


IsExeRunning() :-)

EMG
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
How prevent running an application twice ?
Posted: Wed Feb 21, 2007 01:36 PM

Thanks guys.

You were a great help.

My questions has been answered greatfully.

Regards,

Michel

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
How prevent running an application twice ?
Posted: Wed Feb 21, 2007 04:37 PM

If I remember correctly, isExeRunning() doesn't work with MDI apps when there is at least on child window open (since the main window title changes) and it can also fail to work properly if there is a folder of the same name open.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 16
Joined: Sun Oct 23, 2005 03:00 PM
How prevent running an application twice ?
Posted: Fri Mar 02, 2007 05:55 AM
I'm using this code because sometimes HB_ARGV(0) acts weird on some computers, ie. slow start, my app can run twice, etc.

IF IsExeRunning(cFileName(GetModuleFileName(GetInstance())))   //cFileName(HB_ARGV(0))
   msgalert("Program already running!"+CRLF+"This program cannot be started more than one instance!")
   QUIT
ENDIF

Continue the discussion