Page 1 of 2

don´t run App twice

Posted: Wed May 27, 2020 9:42 pm
by AUGE_OHR
hi,

how to avoide to run 2nd Instance of App under harbour / HMG :?:

Re: don´t run App twice

Posted: Wed May 27, 2020 10:12 pm
by dragancesu
see in help

SET MULTIPLE ON | OFF [ WARNING ]

Re: don´t run App twice

Posted: Wed May 27, 2020 11:29 pm
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:

Re: don´t run App twice

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

Re: don´t run App twice

Posted: Thu May 28, 2020 7:15 am
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:

Re: don´t run App twice

Posted: Thu May 28, 2020 7:31 am
by serge_girard
Great!

Re: don´t run App twice

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

Re: don´t run App twice

Posted: Thu May 28, 2020 10:18 am
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:

Re: don´t run App twice

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

Re: don´t run App twice

Posted: Thu May 28, 2020 12:09 pm
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: