Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
? IsRunning(YourApplicationUNIQUEString)
FUNCTION IsRunning(tcSemaphoreName)
LOCAL lpszSemName
#Define ERROR_ALREADY_EXISTS 183
Declare Integer GetLastError In win32API
Declare Integer CreateSemaphore In WIN32API ;
string @ lpSemaphoreAttributes, ;
LONG lInitialCount, ;
LONG lMaximumCount, ;
string @ lpName
aladin_href = CreateSemaphore(0,0,1,tcSemaphoreName)
RETURN (aladin_href # 0 .AND. GetLastError() == ERROR_ALREADY_EXISTS)
DO DupStart
PROCEDURE DupStart
#DEFINE SW_NORMAL 1
#DEFINE SW_MAXIMIZE 3
#DEFINE SW_MINIMIZE 6
DECLARE Long FindWindow in user32 String, String
DECLARE Long BringWindowToTop in user32 Long
DECLARE Long ShowWindow in user32 Long, Long
LOCAL lnHWND,lcTitle
lcTitle = _screen.Caption
_SCREEN.Caption = Sys(3)
lnHWND = FindWindow(null,m.lcTitle)
_SCREEN.Caption = m.lcTitle
IF m.lnHWND >0
=messagebox("This program is already running "+ ;
"(or make up your own words)"+ ;
space(10),0+64+0,"System Message")
BringWindowToTop(m.lnHWND)
ShowWindow(m.lnHWND,SW_MAXIMIZE)
QUIT
ENDIF
ENDPROC
************************************************************
* FUNCTION FirstInstance()
************************************************************
* Author............: Gary Foster, Pointsource Consulting, Inc. 104171.3677@compuserve.com
* Project...........: Starbase
* Created...........: 03/13/98 15:39:58
* Copyright.........: Public Domain
*) Description.......: This function uses the creation of a named MUTEX
*) : to determine existing instance of an application.
*) : Call this function very early in an application's
*) : startup to create a named object that can be checked
*) : every time the application is started. If the named
*) : object exists, the function will try to bring foreward
*) : the applications main frame. In this case, the main frame
*) : is the FoxPro _SCREEN. Any other hWnd would do as well.
*) :
* Calling Samples...: IF !FirstInstance()
* : QUIT && Or something along that line.
* : ELSE
* : yada yada yada...
* Parameter List....:
* Major change list.:
************************************************************
FUNCTION _FirstInstance()
PARAMETERS __MUTEX
*-- Declare just enough API functions and constant defines to support this function.
#DEFINE SW_RESTORE 9
#DEFINE ERROR_ALREADY_EXISTS 183
#DEFINE GW_HWNDNEXT 2
#DEFINE GW_CHILD 5
DECLARE INTEGER CreateMutex IN win32api INTEGER, INTEGER, STRING @
DECLARE INTEGER CloseHandle IN win32api INTEGER
DECLARE INTEGER GetLastError IN win32api
DECLARE INTEGER SetProp IN win32api INTEGER, STRING @, INTEGER
DECLARE INTEGER GetProp IN win32api INTEGER, STRING @
DECLARE INTEGER RemoveProp IN win32api INTEGER, STRING @
DECLARE INTEGER IsIconic IN win32api INTEGER
DECLARE INTEGER SetForegroundWindow IN USER32 INTEGER
DECLARE INTEGER GetWindow IN USER32 INTEGER, INTEGER
DECLARE INTEGER ShowWindow IN WIN32API INTEGER, INTEGER
DECLARE INTEGER GetDesktopWindow IN WIN32API
*-- We need a function from Foxtools. I know I could get this from the API, but I'm lazy.
* IF !("FOXTOOLS" $ UPPER(SET("LIBRARY")))
* SET LIBRARY TO FOXTOOLS.fll ADDITIVE
* ENDIF
LOCAL cExeFlag && Name of the MUTEX
LOCAL nExeHwnd && MUTEX handle
LOCAL hWnd && Window handle
LOCAL lRetVal && Return value of this function
*-- Try and create a new MUTEX with this name.
cExeFlag = __MUTEX + CHR(0)
nExeHwnd = CreateMutex(0,1,@cExeFlag)
*-- If the named MUTEX creation fails because it exists already, try to display
*-- the existing application and have this function return .F., presumably
*-- to a calling routine that is deciding whether to continue instantiation.
IF GetLastError() = ERROR_ALREADY_EXISTS
*-- Get the hWnd of the first top level window on the Windows Desktop.
HWND = GetWindow(GetDesktopWindow(), GW_CHILD)
*-- Loop through the windows. If the application has no top level window,
*-- the loop will quickly run out of desktop windows and simply exit.
DO WHILE HWND > 0
*-- Is this the proper window? GetProp looks() for a property we added
*-- the first time, not a caption.
IF GetProp(HWND, @cExeFlag) = 1
*-- If the application window is minimized, open 'er up to the
*-- previous state.
IF IsIconic(HWND) > 0
ShowWindow(HWND,SW_RESTORE)
ENDIF
*-- Show me the money, oops, I meant the window, Show Me The Window!
SetForegroundWindow(HWND)
*-- Our work here is done, ride off into the sunset.
EXIT
ENDIF
*-- Get the next window handle.
HWND = GetWindow(HWND,GW_HWNDNEXT)
ENDDO
*-- Close the 'failed to open' MUTEX handle, we don't need it any more.
CloseHandle(nExeHwnd)
lRetVal = .F.
ELSE
*-- Add a property to the FoxPro main frame so we can identify this
*-- window again regardless of caption changes.
SetProp(application.HWND, @cExeFlag, 1)
lRetVal = .T.
ENDIF
CLEAR DLLS ;
[CreateMutex],;
[CloseHandle],;
[GetLastError],;
[SetProp],;
[GetProp],;
[RemoveProp],;
[IsIconic],;
[SetForegroundWindow],;
[GetWindow],;
[ShowWindow];
[GetDesktopWindow]
RETURN lRetVal
ENDFUNC