LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the panel resource ID from a panel handle ?

Hello,

Is there a way to retrieve the constant panel ID of a panel that was loaded with LoadPanel ?

I can always save this value in a variable when loading the panel, but I would have expected a better solution.

Thanks

0 Kudos
Message 1 of 10
(6,113 Views)

Hello,

 

What do you want to achieve?

 

You can retrieve the panelResourceID from the include file (*.h) of your UI resource file (*.uir). There you will find the definitions, such as

 

#define  PANEL                            1       /* callback function: PanelEvents */

 

But why do you need this information?

0 Kudos
Message 2 of 10
(6,104 Views)

The name assigned to the panel in the UIR editor can be retrieved programmatically with GetPanelAttribute and ATTR_CONSTANT_NAME attribute.

 

But I second Wolfgang in asking you: what do you want to do with it? The only utility I can imagine is to customize callback behaviour based on panel name in case you have the same callback installed on different panels. In this case probably saving panel handles in a global variable is more efficient than dealing with panel names.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 3 of 10
(6,096 Views)

Hello guys,

thanks for replying, I know I can get the panel name with GetPanelAttribute, but I would prefer to avoid dealing with strings. Here is my goal:

I have a main test panel, common to several tests, loaded once, which handle can be called hPanelMain

Into that panel, I have a child panel that is test-specific, which handle can be called hPanelChild => each time the user selects a test, I'm loading the corresponding specific panel from the uir file, and this specific panel is always handled by hPanelChild.

Then, I need to do some treatment according to the panel that was loaded and I need to make a switch/case on the panel resource ID to differentiate that treatment.

At worst, I can memorize the resource ID in a variable when loading hPanelChild but I was expecting to have an existing command to retrieve the ID from the handle.

Thanks

 

0 Kudos
Message 4 of 10
(6,087 Views)

Hi ppsn,

 

I'm not sure I understand exactly your problem but if I do, here is what I suggest :

 

"each time the user selects a test, I'm loading the corresponding specific panel from the uir file, and this specific panel is always handled by hPanelChild.

Then, I need to do some treatment according to the panel that was loaded and I need to make a switch/case on the panel resource ID to differentiate that treatment."

 

If each test has a specific childpanel, then to differentiate my treatment I will test the name of the test or a variable that identifies each test instead of testing the panel resource ID.

 

I hope it will help.

 

Vincent

 

0 Kudos
Message 5 of 10
(6,083 Views)

Actually I still do not understand why you don't like using the panel handle (or saving the panel information in a variable), I would have considered this approach as o.k. Bear in mind that the panel resource ID possibly might change if you modify your UI file

0 Kudos
Message 6 of 10
(6,082 Views)

Hello ppsn,

let's try another approach.

 

The difference in panels is probably related to differences in test specifications and / or hardware used to perform tests. How you discriminate these situations? I don't suppose you want to discriminate relying on panel ID, you'll have some program parameter that is loaded with the appropriate value when the oprator chooses which test to perform.

Well, the same criteria can help you in differentiating among panels where to display results / get settings or so.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 10
(6,074 Views)

Hi Vincentk,

I also started with your idea of switch-casing the tests, but the fact is that it is more complex: a same specific-test panel can be used for different tests and there's a lot of different tests and configurations. Also, more tests may be added in the future, using the existing panels => I started to have complicated switch/cases and there was the risk of forgetting to add new test cases for future developpements => that's why I changed my idea to switch-casing the panel IDs instead of switch-casing the tests selected by the user: treatment is more simple and already done for all tests, even not yet existing tests.

 

Hi Wolfgang,

I know the IDs can change but this is not a pb as I'm casing with ID constant names and not values (ex. switch(panelID) {case PNL_A: break; case PNL_B: break;....}

When the user click on a button on the child panel, the callback receives the panel handle, not the panel ID, that's my problem.

 

Concrete example of my need:

The users selects a valve to open (toggle button) on the child panel => as only one valve at a time can be selected, I need to switch off other valves (other toggle buttons) => in the callback I would like to have this simple code:

 

CVICALLBACK SelectValve(int activeChildPanel, int activeControl, ...)

{

    int nValve, nCtrl;

    if (event == EVENT_COMMIT)

           for (nValve=0; nValve<g_NbOfValves; nValve++)

           {

                 nCtrl = MyGetValveCtrl(panelID, nValve)              // Here is the pb: how to get panelID constant from activeChildPanel handle

                 if (nCtrl != activeControl) SetCtrlVal(activeChildPanel, activeControl, FALSE);

           }

}

 

and in another file, I have a simple function that can return all valves control IDs depending on panel IDs:

 

int MyGetValveCtrl (int panelID, nValve)

{

    switch (panelID)

    {

          case PNL_A:

                    switch (nValve)

                    {

                               case TV1:   return PNL_A_TV1;

                               case TV2:   return PNL_A_TV2;

                               ...

                    }

          break;

 

          case PNL_B:

                    switch (nValve)

                    {

                               case TV1:   return PNL_B_TV1;

                               case TV2:   return PNL_B_TV2;

                               ...

                    }

          break;

 

          .....

    }

}

 

 

But no matter, my question was: "is there a way to get panel ID from a panel handle". If there's no mean, I will store the panel ID in a global variable when loading the child panel.

Thanks for comments.

 

0 Kudos
Message 8 of 10
(6,070 Views)

@ppsn wrote:
                 nCtrl = MyGetValveCtrl(panelID, nValve)              // Here is the pb: how to get panelID constant from activeChildPanel handle

 


On the risk of misunderstanding you: you can get the active child panel by looping through all panels (using ATTR_FIRST_CHILD and ATTR_NEXT_PANEL) and querying the attribute ATTR_ACTIVE

Once you know the active panel you know its panel handle and from this you can also get the can get the attribute ATTR_CONSTANT_NAME.

0 Kudos
Message 9 of 10
(6,063 Views)

As I have many specific panels, I only load them when needed and each of them is loaded into the same panel handle as only one child panel can be used and displayed at a time.

 

Thanks you all for your answers, consider the subject as closed.

Now I know I didn't miss any unknown CVI function or parameters that could give me back a panel ID through its handle. I will save this value when loading the panel or use the constant name instead of the constant ID.

Bye.

0 Kudos
Message 10 of 10
(6,059 Views)