Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Stop multiple instances
Message
 
À
29/08/2002 21:54:19
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00695284
Message ID:
00696169
Vues:
10
>Dear All,
>
>Anyone can show me how to programmatically prevent multiple instances of running application ?
>
>Tia,
>J.
put this code in a class, thats what I have done. you can just put it in a program and call the program with the parameter.

local WindowName
WindowName = this.windowname

#define GW_OWNER 4
#DEFINE GW_HWNDFIRST 0
#DEFINE GW_HWNDNEXT 2
declare integer SetForegroundWindow in win32api long lnhWnd
declare integer GetWindowText in win32api integer, string, integer
declare integer GetWindow in win32api integer,INTEGER
declare integer IsWindowVisible in win32api integer
declare integer GetActiveWindow in win32api
IsWindEx = .F.
if len(WindowName) < 1
return IsWindEx
endif
foxhwnd = GetActiveWindow() && get the window handle of this window
hwndNext = GetWindow(foxhwnd,GW_HWNDFIRST) && get the handel of the first window

**** loop thru each window to search the title
DO WHILE hwndNext <> 0
*** if window is not the foxpro handle and not a child window
IF (hwndnext <> foxhwnd .AND. GetWindow(hwndnext,GW_OWNER) = 0)

Stuffer = SPACE(64)
x = GetWindowText(hwndnext,@Stuffer,64) && get the window text
*** check to see if this is the specified window.
IF WindowName $ Stuffer
IsWindEx = .T.
=SetForegroundWindow(hwndnext) && BRING WINDOW TO FRONT
EXIT
ENDIF
ENDIF
hwndNext = GetWindow(hwndnext,GW_HWNDNEXT)
ENDDO
RETURN IsWindEx

from the main program before you do anything
objCheckRun = createobject("checkrun")
if type('objCheckRun') = 'O'
objCheckRun.windowname = "PC Matrix"
if objCheckRun.checkrun()
release objCheckRun
quit
endif
endif
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform