LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Labwindows/CVI applications & stealing focus

Any insights as to why my CVI applications like to steal the focus from other applications? Let me try to explain.

Anyone familiar with Microsoft's TweakUI utility will know that there is an option in there to prevent applications from stealing focus. This is very nice, as it prevents things like an instant messenger program from popping up over what you are doing. Also, this prevents CVI based applications from stealing the focus everytime a DisplayPanel(...) or an InstallPopup(...) is called (or at least it should, more below). On my computer with CVI (I'm using 7.1), I noticed that this option keeps getting reset to disabled.

I did some research, and found that the TweakUI setting is modifying the registry, the key is named "ForegroundLockTimeout" in "Control Panel\\Desktop" in HKEY_CURRENT_USER. As I suspected, something keeps on setting this key to 0 (disabled).

I downloaded RegMon from Sysinternals, and to find the offending program(s). As it turns out, CVI is setting this key to 0 everytime I debug a program. Furthermore, if I make a distrobution kit and install it on this computer, the key is set to 0 everytime I run the application.

As a fix, I tried making my CVI program set the key to 200000 (enabled) immediately upon start up. However, this doesn't seem to help with the CVI based application stealing focus, as I'm guessing that the application's behavior is determined at startup and by the time I reset the key it's too late. As an attempted workaround, I even made a program (in CVI) that checks this registry key every second, and it it finds that is has been changed it changes it back. This didn't help either.

Any insight as to what is going on here? I would like my program to be able to work in the background when needed, but this issue keeps on making it pop up over other applications. Thanks.
0 Kudos
Message 1 of 12
(5,250 Views)

Hello tstanley,

The CVI debugger sets that option based on the following registry setting:

Key: HKEY_CURRENT_USER\Software\National Instruments\CVI\7.1\Environment
Item: SetForegroundLockTimeOut

Try changing that item's value in the registry to see if it fixes your problem.

Luis

0 Kudos
Message 2 of 12
(5,227 Views)
Luis,

Thanks for your reply. I changed the key as you suggested to "False", and my application now behaves much better. When I get time I'll have to see how things work on a computer that doesn't have CVI installed but will be running my application.

-Todd
0 Kudos
Message 3 of 12
(5,215 Views)

Hi, Todd.

When you run your application by itself, you shouldn't have any problem, since it is the CVI debugger -- not the application -- that is setting that flag (so that it can bring itself to the foreground when your application hits a breakpoint). That registry key doesn't even exist in a machine where CVI isn't installed.

Luis

0 Kudos
Message 4 of 12
(5,187 Views)
I tried this fix and it does not work for me. This is a major source of frustration.
0 Kudos
Message 5 of 12
(5,033 Views)
Can you describe in some detail what the exact problem you're having is, as well as which version of CVI you're using?

Thanks,
Luis
0 Kudos
Message 6 of 12
(5,014 Views)
I'm using Labwindows 7.1.1 (314). Any time I build and debug my code, it changes the registry back to allow the program to take focus. It appears that this does not happen if I run the debug .exe file on its own. It seems to only do it if I run the program through CVI.

0 Kudos
Message 7 of 12
(4,999 Views)
I assume you already set the value of HKEY_CURRENT_USER\Software\National Instruments\CVI\7.1\Environment\SetForegroundLockTimeOut to 0? Did you make sure that CVI wasn't running when you changed that value in the registry? (Otherwise, CVI would overwrite it to what it thinks the value should be when it exits).

Luis
0 Kudos
Message 8 of 12
(4,980 Views)
I've noticed that this settings appears to also be set as part of a project or workspace.  I can make my computer work, but if I start working with a project/workspace created on another computer that doesn't have this set, then CVI will ignore its registry setting and set the ForegroundLockTimeOut anyway.  Eventually, I can make the copied project behave by repeatably setting the ForegroundLockTimeout back until it stops doing it, but whenever I have to work on another copied project I have to start the fight all over again.
0 Kudos
Message 9 of 12
(4,926 Views)

Does CVI 2010 no longer look at this registry key?  I have 'SetForegroundLockTimeOut' set to 'False', yet it seems that CVI 2010 sets my ForegroundLockoutTime to 0 every single time I click on "Debug Project".  Thanks.

0 Kudos
Message 10 of 12
(4,057 Views)