08-30-2012 11:38 AM
I'm using LV 2012 on Windows 7. I have a LV built executable whose window is commonly minimized by users. Since there can only be one instance of the exe, if a user attempts to click the shortcut while the exe is already running, nothing happens. I'd prefer that my app window instead open and move to the front. I'd swear that LV executables used to do this all on their own, though I don't know if that is due to a change in LV or to Windows. I'm willing to do it programmatically, but no event seems to get triggerend when you "re-launch" the exe. Anybody know a trick for doing this?
08-31-2012 11:58 AM
There is not a direct way to build the executable so that it is brought to the front of your screen if that executable is already running. There are ways to modify VIs in VI propertiesso that they initially move to the front of the screen upon opening, but nothing of that sort exists for executables. However, there are two programmatical methods of finding and moving your executable to the front of the screen that you can see here.
https://decibel.ni.com/content/docs/DOC-4745
https://decibel.ni.com/content/docs/DOC-4551
Regards,
Mr. Moore
08-31-2012 12:10 PM - edited 08-31-2012 12:12 PM
There may be an easier way, but...
You could modify your INI file to allow multiple instances of the program. Then in the program you can set it so it does NOT show the front panel at startup and add a check at startup using "Find Window" from the windows API to determine if the window already exists. If it does (i.e. you get a valid handle) you can use that handle to move the already running window to the front (also using the windows API as was suggested above) and quit the program, because another instance is already running. If it does not exist, then use a property node to show the front panel.
The only possible issue here is, you will always get a valid handle to the window since yoru program will be running because you just opened it, whether it is the first or second instance. I am not a windows API wiz by any means, but you may be able to determine if you get multiple handles vs. if you just get one valid handle for a window name, and use that logic to your advantage. This is just a stab in the dark.