Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Checking for single instance of a VFP exe
Message
 
To
20/05/1999 04:15:18
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00220668
Message ID:
00220977
Views:
25
>>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


Arnon,

Thanks to you, Evan and James for the help. But I'm still pretty new to all this stuff, so maybe a little more direction would help.

I have a small VFP program called qdmsstart.exe (shown below) that first checks the filedate of the local copy against that of the server (the "master" copy). If they are the same, it launches qdms.exe using the VFP run command. If not, it prompts the user to either update the local copy or return to Windows.

I'm not sure how to incorporate your code into this. Obviously, I don't want any of the checking for an already-running instance to occur until the user has agreed that its time to RUN the .exe

Help? Thanks :)

(oh...and what the (*&@#% is a MUTEX? LOL)

************************************************************************
CLOSE ALL
Clear ALL
#Include MsgBox.H

IF fdate('c:\qdms2000\qdms2000.exe',1) < fdate('\\stdsrv01\kdrive\qa\qdms2000\qdms2000.exe',1)
	IF messagebox("Your QDMS application software requires updating."+chr(13)+chr(13)+;
	"This process will only take a few seconds."+chr(13)+chr(13)+"Press OK to update, or CANCEL to return to Windows.",;
			D_Nexclamation+d_nokcancel,"QDMS 2000 Software Update")=d_nok
		SET safety off
		COPY file ('\\stdsrv01\kdrive\qa\qdms2000\qdms2000.exe') to ('c:\qdms2000\qdms2000.exe')
		COPY file ('\\stdsrv01\kdrive\qa\qdms2000\readme.txt') to ('c:\qdms2000\readme.txt')
		SET safety on
		IF messagebox("Update complete!"+chr(13)+chr(13)+"Would you like to view the README file for the updated software?",;
				D_Ninformation+d_nyesno,"QDMS 2000 Software Update")=d_nyes
			RUN /n1 c:\windows\notepad.exe c:\qdms2000\readme.txt
		ENDIF
	ELSE
		QUIT
	ENDIF
	RUN /n c:\qdms2000\qdms2000.exe
ELSE
	RUN /n c:\qdms2000\qdms2000.exe
ENDIF
Phil Thomas
http://phillipdthomas.com

Never let your energy or enthusiasm be dampened by the discouragements that must inevitably come.....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform