Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run another vfp application in background or hidden mode

Status
Not open for further replies.

parammodi

Programmer
May 22, 2010
5
IN
Hello,

I am using VFP 6.0
I have one vfp exe child.exe which i want to run from another parent.exe

I want to run it in background i.e. child.exe should not come as front screen but child.exe has the main form with
showwindowstate = 2 As Toplevel Form

I want to run child.exe and also want to wait will it is completed. Cannot make any changes to child.exe

I tried launching a timer from parent.exe (main exe) which will bring another dummy form on child.exe screen

But it also goes behind child.exe form

Please help me

Thanks in advance
 
Welcome to the forum.

The usual way to run one EXE from another is with ShellExecute() - see for further details.

However, that won't meet your requirement to pause Parent.EXE until Child.EXE is finished. To do that, you need to use Windows Scripting:

Code:
oWSH = CREATEOBJECT("wscript.shell")
oWSH.Run("c:\Mypath\Child.Exe", 2, .T.))

The .T. in the third parameter tells the calling program to wait until the child has finished executing.

The 2 in the second parameter tells the child to run minimised (that way, parent will stay in front).

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hello,

Thanks for your suggestion but since the child.exe has a main form as showwindowstate=2 it popups up the mainform.
So my purpose of minimizing is not solved

It does wait for the child.exe to complete its execution.

One way i was trying to put a timer in parent.exe that would bring a dummy form on screen after child.exe has started running and hide its screen
but since parent.exe will wait for completion of child.exe i am not able to use that also.

Is there any other way?

Thanks again and guide me





 
If you have no chance to change child.exe you can only care about your application becoming foreground window again. There's SetForegroundWindow API for that...

But you can't run the child exe and wait for it and at the same time run SetForegroundWindow. You could try via Timer.

Put that in a prg and adapt to your situation:
Code:
DECLARE INTEGER SetForegroundWindow IN user32 INTEGER hwnd
oWSH = CREATEOBJECT("wscript.shell")
oTimer = CreateObject("ForegroundTimer")
oWSH.Run("c:\Mypath\Child.Exe", 2, .T.)[s][/s]
oTimer = .NULL.
oWSH = .NULL.

Define Class ForegroundTimer as Timer
   Interval = 50 &&adapt, if this runs too early.
   Enabled = .T.
   Procedure Timer()
      SetForeGroundWindow(_screen.hwnd)
      This.Ebnabled = .F. && just running once is enough.
   Endproc
Enddefine

Anyway, is that really your problem, to stay in front? As you want to wait for the child.exe your user will have to wait anyway, if it's becoming front window or not. Your application window will not be respomnsive as long as execution is on the oWSH.Run() call and waits there, no matter how you parameterize the visibility and size of the child.exe windows(s).

For example put notepad.exe into this WSH.Run call and notepad will run behind the VFP screen. VFP will still wait for this notepad to exit and only continue afterwards. The mouse pointer will turn into the hourglass (or ring) and only exiting notepad.exe makes that go away. VFP is not responsive while notepad.exe runs, as it executes the WSH.Run and pauses there.

So this is cannot really be your intention, even if child.exe does something on it's own and also automatically finishes, you typically only wait for a secondary process, if you want something back from it. And if it takes long you want it to run in parallel and during that time your users should be able to do anything else. Then you'd run the child.exe without waiting for it and instead let something in your app wait for a result file or anything else coming back, eg in a timer.

Bye, Olaf.
 
First of all sorry for late reply, i was away because of health issue.

Thanks for your continued interest

@Olaf : My concern to hide the screen of child.exe is because child.exe has something displays some information which is no longer relevant so I want to hide that, as well as wait for the child.exe to complete.

Thanks for the code you supplied but since we are passing .t. in

oWSH.Run("c:\mypath\child.exe", 2, .t.)

the control never returns to parent.exe so timer event is not fired

can you suggest something

@mike i tried with all the parameters but still same problem arises child.exe screen is visible only

Thanks for your continued support
 
>the control never returns to parent.exe so timer event is not fired

Have you treid what I say and put in notepad.exe? The timer event does run, because the timer is started before the Run call of the child executable. And while the main program pointer waits for the exit of the child process the timer event happens when it happens, it's not in the normal course of the program.

So the "secret" is to start a timer before the child process.
The timer interval just has to be fiddled with, so the child window exists and the SetForeGround window puts your app window in the front. If the timer event happens too early the child window appears in front after the parent window was set front.

So you might need to fiddle with the interval and you might have _screen hidden, then use another window hwnd of the window you want in the front.

Bye, Olaf.
 
Hello,

Thanks for your suggestion Olaf

I tried with notepad.exe our solution works perfect.

But with my child.exe still not able to get desired result.

I have tried changing timer intervals also increasing upto 1000 but still not getting result

Thanks
 
It can take a few seconds until the window appears. Have you simply counted from the Run to the appearance of the child.exe?
And is your application window display size? Is it large enough to hide the child application window?

You say it's a VFP app, but you don't have the code?
No matter what you input in the Run command as initial window state, the vfp code can of course set _screen.visible or set AlwaysOnTop, then there is nothing against that, but also trying AlwaysOnTop for your own application window. I fear the last one stating AlwaysOnTop for his window will put it in the front.

There is nothing, that you can do from outside, if the child application even reacts to window resize or other events and puts its window back to top.

Bye, Olaf.
 
Hello,

Thanks for your suggestion and I guess child.exe i will try the timer in more detail as you suggested

And inform you about the same

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top