From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Starting an application - WITHOUT stealing the focus

Hi All,
I want to start another program (exe) from my cvi exe - but I want it to not steal the focus of the calling program. Its a data logging display.
I can do this with ShellExecute (w/ SW_SHOWNA param) - but not with LaunchExecutableEx() - all attempts to send the requested prog to the background (SetForegroundprocess, etc.) failed.
The problem with just using ShellExecute is the need to determine whether or not the spawned process is still running (ie. ExecutableHasTerminated()). This function requires a CVI handle - which I cannot get from ShellExecute.

Any suggestions?

Thanks!

-Martin
0 Kudos
Message 1 of 5
(3,011 Views)
LaunchExecutableEx() has an argument called Window State. Two options to look at:
LE_SHOWNA: The application's window is shown normally but is not activated
LE_SHOWMINNOACTIVE: The application's window is shown as an icon but is not activated
Open the function panel for LaunchExecuteableEx and look at the help.
0 Kudos
Message 2 of 5
(3,011 Views)
Hi Al,

That was my first thought as well - but these flags (LE_SHOWNA, LESHOWMINNOACTIVE) seem to be ignored (CVI 7.0) - the called app is in focus and highest z-order regardless of the chosen Window state.

Do I have a bad setting or option somewhere?

Thanks!
0 Kudos
Message 3 of 5
(3,011 Views)
Look at the attached project. I created it in CVI 6.0 and tested it in 7.0 Evaluation. It uses LaunchExecutableEx to launch notepad with the Window State controlled by a ring. It can launch and terminate notepad minimized, inactive, etc.
If you're trying to launch your app the same way, maybe there's something in that app forcing it to be on top. Try launching notepad from your app and see if that works.
0 Kudos
Message 4 of 5
(3,011 Views)
Here are a couple of ideas:

You can make the CVI window allways visible right before calling your application. You can set back this propertie to the previous state once the aplpication is launched.

Also you can install a popup panel that the launches the executable and tells that user that the app is being launched, then you close the popup and come back to your application.

The third option would be to use Windows SDK functions to force a window to be active and/or set the z possition.

I hope this helps.

Juan Carlos
N.I.
0 Kudos
Message 5 of 5
(3,011 Views)