Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Checking for single instance of a VFP exe
Message
De
20/05/1999 04:15:18
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00220668
Message ID:
00220720
Vues:
33
>Hi all,
>
>I would like to be able to check to be sure that the exe being called by a VFP program isn't already running (minimized or behind another window) and if it is, just maximize or bring it to the front.
>
>I found a KB article but it didn't apply to VFDP 6.0, which I am using. Any help would be GREATLY appreciated!
>
The following code will acomplish that = this is from the March 1999 issue of the VFUG newsletter
LOCAL lhWnd,lhMutex,lcMutexName,llFound,llQuit

llFound=.f.

* Declare some API functions 
DECLARE Integer GetWindow in win32api Integer,Integer
DECLARE Integer ShowWindow in win32api Integer,Integer
DECLARE Integer GetDesktopWindow in win32api
DECLARE Integer SetForegroundWindow in win32api Integer
DECLARE Integer GetForegroundWindow in win32api
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

* Define the Mutex
lcMutexName=const_APPLICATIONNAME+CHR(0)
lhMutex=CreateMutex(0,1,@lcMutexName)

if GetLastError()=183 
    * Mutex Already Exist - locate the original application 
    lhWnd=GetDesktopWindow() && handle to the desktop
    lhWnd=GetWindow(lhWnd,5) && get the first child of the desktop

    do while lhWnd>0 and !llFound && loop until we find the window or run out of windows
        if GetProp(lhWnd,@lcMutexName)==1
            if IsIconic(lhWnd)>0 
                ShowWindow(lhWnd,9)
            endif
            SetForegroundWindow(lhWnd)
            llFound=.T.
        endif
        lhWnd=GetWindow(lhWnd,2) && get handle to the next child of the desktop
    enddo
    CloseHandle(lhMutex)
    llQuit=.T.
else
    * this assumes our application window is currently active 
    lhWnd=GetForegroundWindow()

    * To help identify the application window we are adding
    * a property to it - which we can later search for
    SetProp(lhWnd,@lcMutexName,1)
    llQuit=.F.
endif
Arnon
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform