Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Pete Sass
  Where is Pete Sass?
 Marathon, Ontario
 Canada
 Pete Sass
 To: zakaria hamieh
  Where is zakaria hamieh?
 beirut
 Lebanon
 zakaria hamieh
 Tags
Subject: RE: RUNNING EXE
Thread ID: 104555 Message ID: 104648 # Views: 1 # Ratings: 1
Version: Visual FoxPro 8 Category: General VFP Topics
Date: Friday, August 18, 2006 6:45:41 PM         
   


> Hi all
>
> i have a menu that called from exe file .
> from within this menu i call other exe files (all made in vfp)
> when the user press to close this form the computer will shut down.
> what i need is there a way to check if there is any exe that is running before shutting sown the computer so i will not damaj any database or programes.
>
> b.regards
> zakaria
> foxes will always be running



Hi,

In order to do what you want to do and in the easiest manner.

1. Declare this bit of code in your main.prg startup program:
DECLARE INTEGER GetActiveWindow ;
IN Win32API
DECLARE INTEGER GetWindow IN Win32API ;
INTEGER hWnd, INTEGER nType
DECLARE INTEGER GetWindowText IN Win32API ;
INTEGER hWnd, STRING @cText, INTEGER nType

2. OK now add this function as a PRG into your project:
FUNCTION IsRunning
* Generic routine to check if a given
* application is running on the user's system.
* Parameter is all or part of the window's title.
LPARAMETER tcTitle

hNext = GetActiveWindow()
&& current app's window

* iterate through the open windows
DO WHILE hNext<>0
cText = REPLICATE(CHR(0),80)
GetWindowText(hNext,@cText,80)
&& get window title
IF UPPER(ALLTRIM(tcTitle)) $ UPPER(cText)
* parameter text is present in window title
RETURN hNext
ENDIF
hNext = GetWindow(hNext,2)
&& next window
ENDDO

* required window not found
RETURN 0
ENDFUNC

This function will return a postive number if the application is running, and
zero if the application is not running.

You pass of to the Isrunning() function the windows caption of the window/application
that is running like:
nIsRunning=IsRunning("Microsoft Visual Foxpro")
If nIsRunning > 0
* --- App is running.
ELSE
* --- App is not running.
ENDIF

IsRunning() function as I mentioned returns a positive number if the application
is running and zero if it is not.

You can now run through all the potential VFP applications that are running
and know which ones are in fact running. If you have a potential of 5 sperate
exe's running you need to have the DO CASE... ENDCASE logic to test to see
if any of the 5 sperate applications are in fact running.

OK now you know after testing only application2 is in fact running and now what?

As Ken mentioned, now you need a way to gracefully shut down the secondary
application in a normal fashion.

To perform this correctly you need a timer event to test for something to
envoke the ON SHUTDOWN event in each seperate application. This could be
the existance of a shutdown.txt file that the timer event tests for and
if the timer sees the "shutdown.txt" file it deletes the "shutdown.txt" file
and fires off the ON SHUTDOWN event that does the following:
1. Advises the user that they have other applications running, close them,
or Abort closing down the application.
2. If the user decides to close down the application totally, create the
"shutdown.txt" file.
3. The timer event looks for IF FILE("shutdown.txt") exists and if this
file is seen, call the ON SHUTDOWN event in the seperate application.
4. Don't forget to delete the "shutdown.txt" file and then do what-ever
clean up code you wish such as:
FLUSH
CLOSE DATABASES All
QUIT


Another way of handling this is to set a global memory variable to .T.
for each application the user calles from the main menu, and set the
memory variable flag back to .F. when the seperate application is closes.
In this way you know what application is open and which application is
closes. You still need a trigger event with a timer to properly shut down
the seperate applications that you may have called from the main menu.

Personally, although others at this site look down on the use of global
PUBLIC memory variables, this is a good case to use them.

Another approach is to not allow the closure of you main application and
force the user to save and exit each seperate exe running prior to exiting
your main application where your main menu calls reside.

Hope this gives you fuel for thought as to what approach you want to follow
with your application.

Pete from the Great White North. (Only in Canada, ay.) Over and Out ...

ENTIRE THREAD

RUNNING EXE Posted by zakaria hamieh @ 8/17/2006 3:09:17 PM
RE: RUNNING EXE Posted by Ken Murphy @ 8/17/2006 3:56:16 PM
RE: RUNNING EXE Posted by Pete Sass @ 8/18/2006 6:45:41 PM
RE: RUNNING EXE Posted by Chris Chamberlain @ 8/19/2006 9:44:56 AM
RE: RUNNING EXE Posted by Marcia Akins @ 8/19/2006 1:13:25 PM
RE: RUNNING EXE Posted by Borislav Borissov @ 8/19/2006 8:37:25 PM
RE: RUNNING EXE Posted by Chris Chamberlain @ 8/20/2006 9:17:06 AM
RE: RUNNING EXE Posted by zakaria hamieh @ 8/20/2006 9:24:10 AM