Mandy,
are you with me/us? I want you to undertand what you're trying is quite fruitless. Because if you don't even know what code or behavior in your one EXE takes long, what do you want to move to a second EXE. It becomes very useless to show you in which way to start two exes so the first one stays in the foregound, if you don't even know what to make the second EXE do. Then you have a mechanism but still no solution. I want to help you, I really want to solve your problem. But I can't, if I know nothing about it.
Okay, I hope the first lesson has been clear: Every VFP EXE you start will take the foregroundwindow state, even if it starts no form, it will go to the _VFP system variable, which indeed also is a form. It doesn't matter that this is invisble, this also means if the background EXE starts as second process, it will take the foregroundstate from the foregound EXE. And what's most importat: It doesn't matter that your foregrround EXE had used SetForegroundWindow, this is not a function to tell the OS this should be the permanent foreground window unless you say otherwise. The OS will switch this, the user can switch this. Otherwise there could be all kind of malware that takes Windows as hostage as it does not allow the user to pick what window he wants to use. This is not what the OS will allow.
From this information you could learn that starting the foreground EXE as second exe would work. Well, if two processes start at almost the same time, their loading and initialization process can take slightly different times and you sometimes end up with a frontend in focus and sometimes not.
Lesson 2 / Realization 2:
Mandy, so how do you get the foreground state to the foreground EXE, if you can't be sure how Windows starts what is in the autostartfolder and how it turns out, depending on a gazillion other things all starting when the computer starts? How can you gain full control of what happens? You have to start one EXE from the other, so there is a definite starting order. And I already told above
myself said:
the main GUI exe should start its background processing EXE and not Windows Autostart folder, which gives you no guaranteed order of ecxecution
Why not the other way around? Well, becuase if you start the second non GUI EXE first, let it start the other EXE with the forms, then the UI becomes the child process of the background process. And that's bad, because of what I already showed you:
SetForegroundWindow said:
The system restricts which processes can set the foreground window. A process can set the foreground window only if one of the following conditions is true:
The process is the foreground process.
The process was started by the foreground process.
The process received the last input event.
There is no foreground process.
The process is being debugged.
The foreground process is not a Modern Application or the Start Screen.
The foreground is not locked (see LockSetForegroundWindow).
The foreground lock time-out has expired (see SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo).
No menus are active.
Not only SetForegroundWindow has such privilidge restrictions. You want your main process to be the one that starts the background, even though then the background EXE is started last and removes the foreground state. But now you have it in your hands to forward the Hwnd to the background EXE and make it the first task to do for it, to set the foreground back to the first EXE. That's how you solve this.
first EXE main.prg:
Code:
* initializations...
*...
*...
*... whatever code you need to start with
Local lnHwnd, lcHwnd
Declare Integer GetForegroundWindow In Win32API
lnHwnd = GetForegroundWindow()
lcHwnd = Transform(lnHwnd)
RUN /N second.EXE &lcHwnd
Read events
second EXE main.prg:
Code:
LPARAMETERS tcForegroundHwnd
If pcount()<1
quit
Endif
Local lnHwnd
lnHwnd = Val(tcForegroundHwnd)
DECLARE INTEGER SetForegroundWindow IN WIN32API INTEGER
SetForegroundWindow(lnHWnd)
*...
*...
This at the start of the second EXE makes your first exe the foreground again.
There's still no guarantee at the starrt of a computer, no other application will also start and get the foreground state, you're really lamenting about a thing that may need a click from the user anyway, when there are further windows starting on the desktop. Even if your own two EXEs play their role with each other. On Windows, your application is never alone. So, it's actually a detail solution that will not really bring you forward a decent step towards untangling what would really help to improve the responsiveness of the first EXE - without a second EXE.
Mandy, I beg you please don't continue even if that solves your problem, you still have to think about how to communicate between these processes, and how to ensure if the first EXE is quit by the user, the second EXE also quits to not leave endless running background processes, just because you still only have two processes, but have in no way connected them to each other.
Mandy, in your old thread I gave you code for a COM server. That is not started as a normal EXE, that is started by CREATEOBJECT() with a comserver class name. And that is indeed one way you get a new process that doesn't even cause this problem at all. And you have a reference to that background process, and you can program any method you want iside it. You already have a solution, Mandy, you just disregarded it.
Chriss