LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get Current Active Window

Solved!
Go to solution

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?

0 Kudos
Message 1 of 12
(6,138 Views)
Solution
Accepted by topic author J.New

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.

Message 2 of 12
(6,117 Views)

Excellent.  Thank you.

0 Kudos
Message 3 of 12
(6,078 Views)

Gregory,

 

I am interested in a similar solution.

Can you please save the vi in LabVIEW 2013?

 

- Sable

 

0 Kudos
Message 4 of 12
(5,843 Views)

This will be my first time using the save as previous version function, so hopefully it works for you.

0 Kudos
Message 5 of 12
(5,824 Views)

Works like a charm. Thank you.

0 Kudos
Message 6 of 12
(5,800 Views)

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.

 

Get Active Window.png

Christopher Povey

Principle Test Systems Engineer for BAE Systems.
Message 7 of 12
(5,188 Views)

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?

0 Kudos
Message 8 of 12
(5,176 Views)

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.

Christopher Povey

Principle Test Systems Engineer for BAE Systems.
0 Kudos
Message 9 of 12
(5,165 Views)

Ah interesting, I do tend to keep my VI names pretty short. Thanks for the tip!

0 Kudos
Message 10 of 12
(5,158 Views)