09-20-2018 01:16 PM
Hello. This is my first post. I'm using LV2014 and am developing a container to load with our current application to provide training material to users. I have a while loop that checks a training record to see if the user has viewed the material for the current active screen and prompts them if not. It works, but when I load it in the application, it can't see its own windows. I found the attached vi in a forum somewhere, but don't recall where. It gets the current active window just as long as the window is not part of the application that is running the vi. If I run two instances of the application, each one can get the active window for the other one.
Any ideas?
Solved! Go to Solution.
09-20-2018 02:59 PM
Interesting, I have some very similar code that I use to see if the current VI is active or not, and it works in an executable. It runs the call library function nodes not in the UI thread, you can give it a try.
09-21-2018 01:55 PM
Excellent. Thank you.
05-24-2019 02:06 AM
Gregory,
I am interested in a similar solution.
Can you please save the vi in LabVIEW 2013?
- Sable
05-24-2019 08:38 AM
This will be my first time using the save as previous version function, so hopefully it works for you.
05-25-2019 09:38 AM
Works like a charm. Thank you.
08-04-2020 07:33 AM
I know this is an old thread, but I came across it during a search. Be warned this VI will eventually cause LabVIEW to crash. The reason is it is allocating an empty string to the GetWindowTextA DLL call. The DLL will write to the string (which has been allocated zero bytes of data) and corrupt the memory that follows it!
To fix it use an "Initialize Array" item with an U8 input with a length 256. Convert the U8 array to a string. Then pass this into the DLL call.
08-04-2020 10:57 AM
Hi Christopher, thank you for the suggestion. I have used the code as-is for a couple of years and never had any problems. The documentation says "If the string is as long or longer than the buffer, the string is truncated and terminated with a null character." I have never seen the string terminated either.
Have you seen LabVIEW crash because of this?
08-04-2020 11:38 AM
Yes. I was using the VI above in a Event Handler Timeout for a popup window that I wanted to keep on top. When I clicked on the window behind the window I was interested it came back to the top, but executable then crashed. Same happened when running under LabVIEW.
You might be lucky if the window title is short. I have seen it before with other DLL's that have pointers to strings which have not been pre-allocted. LabVIEW won't do it for you. The DLL will write over you stack, corrupting whatever followed the string location.
08-04-2020 12:15 PM
Ah interesting, I do tend to keep my VI names pretty short. Thanks for the tip!