don´t run App twice

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
AUGE_OHR
Posts: 2062
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

don´t run App twice

Post by AUGE_OHR »

hi,

how to avoide to run 2nd Instance of App under harbour / HMG :?:
have fun
Jimmy
User avatar
dragancesu
Posts: 921
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: don´t run App twice

Post by dragancesu »

see in help

SET MULTIPLE ON | OFF [ WARNING ]
User avatar
AUGE_OHR
Posts: 2062
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: don´t run App twice

Post by AUGE_OHR »

hi,

Code: Select all

SET MULTIPLE OFF
does work ... but i want "more"

when App is already working but e.g. in Tasklist i want to "SetForegroundWindow()"

---

use Xbase++ it does start :
ERRORSYS
DBESYS // RDD
APPSYS
before Main so i have this in AppSys

Code: Select all

PROCEDURE AppSys()
LOCAL cTitle  := "XCM " + VERSION()
LOCAL hWndDlg := @User32:FindWindowA( 0, cTitle )
   IF !( hWndDlg == 0 )
      @ User32:SetForegroundWindow( hWndDlg )
      @ User32:BringWindowToTop( hWndDlg )
      @ User32:ShowWindow( hWndDlg, 1 )
      @ User32:UpdateWindow( hWndDlg )
      // ** It is a second instance....  Bye-Bye
      QUIT
   ENDIF
RETURN
so how do it under harbour / HMG :idea:
have fun
Jimmy
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: don´t run App twice

Post by serge_girard »

Woudl be nice to have!
Serge
There's nothing you can do that can't be done...
User avatar
gfilatov
Posts: 1067
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: don´t run App twice

Post by gfilatov »

serge_girard wrote: Thu May 28, 2020 6:18 am Woudl be nice to have!
Serge,

We have the following simple sample below:

Code: Select all

#include <minigui.ch>

Procedure MAIN
Local cTitle := 'One Instance Sample'
 
OnlyOneInstance( cTitle )
 
DEFINE WINDOW Main ;
   WIDTH 600       ;
   HEIGHT 400      ;
   TITLE cTitle    ;
   MAIN

END WINDOW

Main.Center
Main.Activate

Return


Function OnlyOneInstance( cAppTitle )
Local hWnd := FindWindowEx( ,,, cAppTitle )
 
if hWnd # 0
   iif( IsIconic( hWnd ), _Restore( hWnd ), SetForeGroundWindow( hWnd ) )
   ExitProcess( 0 )
endif

Return NIL
Hope that helps :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: don´t run App twice

Post by serge_girard »

Great!
There's nothing you can do that can't be done...
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: don´t run App twice

Post by mol »

Where is defined function IsIconic?
Is it present in HMG, too?
User avatar
gfilatov
Posts: 1067
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: don´t run App twice

Post by gfilatov »

mol wrote: Thu May 28, 2020 9:39 am Where is defined function IsIconic?
Is it present in HMG, too?
Marek,

Sure.
Please add the following translate statement in your HMG code:

Code: Select all

#xtranslate IsIconic ( <hWnd> ) => IsMinimized ( <hWnd> )
:idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: don´t run App twice

Post by serge_girard »

Hi Grigory, WHat about _Restore in HMG?
Serge
There's nothing you can do that can't be done...
User avatar
gfilatov
Posts: 1067
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: don´t run App twice

Post by gfilatov »

serge_girard wrote: Thu May 28, 2020 10:45 am Hi Grigory, WHat about _Restore in HMG?
Hi Serge,

It is

Code: Select all

#xtranslate _Restore( <h> ) => Restore( <h> )
:idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
Post Reply