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

Moderator: Rathinagiri
Code: Select all
SET MULTIPLE OFF
before Main so i have this in AppSysERRORSYS
DBESYS // RDD
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
Serge,
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
Marek,
Code: Select all
#xtranslate IsIconic ( <hWnd> ) => IsMinimized ( <hWnd> )