Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Smart Start - Saying no to Multiple Instances!
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00271759
Message ID:
00271768
Vues:
21
>For my application, I need some method of not allowing the user to start multiple instances of the executable. If they try to run the same executable, it should simply pop up the currently open executable-- just as many applications already do. I've looked, but can not find an easy way to do this. I'm guessing it includes use of API's of some sort. I would very much appreciate any suggestions on this matter. Thanks.

Here is some code. Author unknown.
**********************************************************
* detects if program is already running
* if it is then it shuts down

FUNCTION ckrun
PARAMETERS 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 .t.
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform