How prevent running an application twice ?

How prevent running an application twice ?

Postby driessen » Wed Feb 21, 2007 1: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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Postby techops » Wed Feb 21, 2007 4:12 am

there is a tmutex class from fivewin.info (Patrick Mast) you should look at
Richard Grayden
Sydney,
NSW Australia
techops
 
Posts: 4
Joined: Wed Nov 29, 2006 11:23 pm
Location: Sydney, Australia

Postby Antonio Linares » Wed Feb 21, 2007 7:53 am

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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42078
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Enrico Maria Giordano » Wed Feb 21, 2007 8:37 am

Antonio Linares wrote:
Code: Select all  Expand view
if Is Exe Running( cFileName( HB_ARGV( 0 ) ) )


IsExeRunning() :-)

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby driessen » Wed Feb 21, 2007 1: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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Postby James Bott » Wed Feb 21, 2007 4: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby yam_hiong » Fri Mar 02, 2007 5: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.

Code: Select all  Expand view
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
User avatar
yam_hiong
 
Posts: 16
Joined: Sun Oct 23, 2005 3:00 pm
Location: Pontianak - Indonesia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 61 guests

cron