LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

child-parent and access to an object of another vi

Hi,

I am using Windows API calls for making Child windows and it works but now I want to make a window (vi) that is a child of another Child window (GrandChild) but It doesn't work. I attach you my vi.

Thanks,

ToNi.
0 Kudos
Message 11 of 21
(2,229 Views)
First of all, allow me to congratulate you on getting this to work. This could be a useful feature and I will think about whether or not I should use it myself for certain things.
The main reason this isn't working for you second window is that FindWindow will no longer help you since it doesn't find child windows, so it can't get the handle to the child window. You have 2 options. You can use FindWindow and build the chain from the bottom (if possible). This means you turn a window into a child, then you turn the parent into a child and so on. This has the disadvantage of only allowing you to add new child windows to the top level parent window.
The second option is to use FindWindowEx which does find child windows. Its structure is slightly different (you can find it in MSDN, use U32 for the handles), but it should work if you give it the right names. You will have to write some logic for when to use FindWindow and when to use FindWindowEx and you will have to modify LabUseful's VI or create a copy of it for this to work.
One last thing you should watch out for is the window names. The names change according to the VI state - If it's running, just the name. If not, there is also "Front Panel". There could also be an asterix. If you give it a unique name, it could also change. This will probably not matter in runtime, but it could be an issue during development.
Last thing, please don't post the same question to multiple threads. The most this can do is annoy people who see they wrote a long response (like this one) and then see that someone already gave a response in another thread. Also, have patience. These things take time.
Hope this helped.

___________________
Try to take over the world!
0 Kudos
Message 12 of 21
(2,216 Views)
Thanks, I am trying to do it now but... I don't know very well how it works, it is a little difficult....

ToNi.
0 Kudos
Message 13 of 21
(2,209 Views)
I am getting problems to do it. Exactly I don't know how to do it.....

Can anyone help me? some idea?

Thanks,

ToNi.
0 Kudos
Message 14 of 21
(2,197 Views)
FindWindowEx has 2 additional parameters which are hWnds (U32). The first is for the top level window and the second can be null. I suggest you write another VI (Create Child N3?), which will accept both inputs for the VI names and either a third input or the hWnd from the previous call and will use the code which is in CC N2 to get a handle for the window that's about to become a child and FindWindowEx to get the hWnd for the window which is about to be the parent. Maybe you should change CC N2 to accept hWnds instead of VI names.
I don't have time to think about this at the moment, but maybe I will tomorrow. In the meantime I suggest you try to implement this and I promise not to forget.

___________________
Try to take over the world!
0 Kudos
Message 15 of 21
(2,194 Views)
OK. Here's a quick version I created. It's very messy and it may have bugs, but it worked for me. Clean it up and test it to see that it works fine.
I added another VI which uses findwindowex and which needs the name of 3 VIs. As a first step, use Embed 2 to embed one window into another. Then, use Embed 3 to embed a window into a child window. If you clean it up, post your results, so other people can use this.

___________________
Try to take over the world!
0 Kudos
Message 16 of 21
(2,191 Views)
Hi,

I am testing your vis. I have 3 windows: test.vi (yours), myVI_MOD.vi and mySubVI_MOD.vi. I want to embed myVI_MOD.vi inside test.vi when I press button embed 3windows2 I created in test.vi. Then when myVI_MOD.vi opens, I want to embed mySubVI_MOD.vi inside myVI_MOD.vi when I press the button call my Subvi. Then myVI_MOD.vi is child of the parent test.vi and mySubVI_MOD.vi is child of myVI_MOD.vi (in this case myVI_MOD.vi would be parent of mySubVI_MOD.vi) but it doesn't work. What's happen?

I attach you my example. I have done it in LV7 express.

Thanks,

ToNi.
0 Kudos
Message 17 of 21
(2,177 Views)
I only had a quick look at your modifications, but I believe at least one problem is that the window name is "Main VI [myVI_MOD.vi] Front Panel" and that's not what you're giving the DLL.
To find this, I opened the create child VI and let the code run once. That way, the values were entered into the controls. Then, I placed probes on the windows handles and on the windows titles and immediately saw that the handle was 0. There may be more of these problems.
In general, this example was just something I put together very quickly and it came out very messy. If you want to keep using it, I suggest you clean it up and maybe place some documentation on the code. Also, you may want to give some thought to the possible windows names. As you can see, the few cases I covered in my code are clearly not enough. If you manage to improve this code, post your results - I'm sure other people would like to have this as well.

___________________
Try to take over the world!
0 Kudos
Message 18 of 21
(2,168 Views)
Hi again,

I am trying to embed 3 windows: I want to embed myVi.vi into Test.vi, and mySubVi.vi into myVi.vi at the same time using your create child2.vi but it doesn't work. Is it possible?

Thanks,

ToNi.
0 Kudos
Message 19 of 21
(2,154 Views)
Not without modifying my VI. This has to be a 2 stage step, because once you embed one window into another, you have to use findwindowex, because the window handle is different. You can modify the code to do this like this:

1. If All inputs are wired, use findwindow and setparent on the relevant window and then use findwindowex to find the new handle and use setparent again.
2. If only 2 of the input are connected, perform only the first step.

This way, the VI will handle both cases.
Like I said previously, this VI is only something I wrote as a quick demo. It's very messy and it doesn't handle all cases. You really should clean it up and document and test it if you plan on using it.

___________________
Try to take over the world!
0 Kudos
Message 20 of 21
(2,143 Views)