LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

access control using panel handle

Solved!
Go to solution

Is there a way to access Constant name when I only have the panelHandle for the UIR. The control is part of different project and panelHandle is passed from first

project to second project. Second project now need to set the value of control but only has access to panelHandle of the first project.

TIA

*************************************************
CLD
*************************************************
0 Kudos
Message 1 of 10
(5,332 Views)

One option is to use the GetActiveControl if you'll make that control on the other panel as the default control...

 

But I don't understand if you don't know the control name how do you expect to use it ? 

 

Even if you'll get all the controls list how will you know the one you want to use ?

-----------------------------------------
Kobi Kalif
Software Engineer

0 Kudos
Message 2 of 10
(5,324 Views)

The constant name is accessible at runtime via GetCtrlAttribute (..., ..., ATTR_CONSTANT_NAME, ...); which returns a string with the name of the control. ATTR_CONSTANT_NAME_LENGHT may help you in determining the size of the string to allocate for the previous attribute.

Ideally you could iterate on all controls in the panel by first calling GetPanelAttribute (..., ATTR_PANEL_FIRST_CTRL, ...); and next looping through GetCtrlAttribute (..., ..., ATTR_NEXT_CTRL, ...); to locate all controls in the panel.

 

The main problem I can see, as I've never run through such a situation, is that the simple panel handle may not be enough for you to access a program resource via a separate application. You will need to investigate on this subject.



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 3 of 10
(5,315 Views)

Thanks Roberto,

 

In order to use the ATTR_CONSTANT_NAME I will need Control ID. Currently from 1st project, only the panelhandle is passed to project 2. Sorry I forgot to mention it in the original post but is there a way to access the Control ID of the 1st project in 2nd project given only the panelhandle of the first project? What I have done is defined the Control ID with the same name  (for example #define PANEL_NUMBER   4) in the header of the second project....but am uncertain if by accessing the panelHandle of the UIR in first project and defining the control ID with the same name in the second project would actually work?

 

 

TIA. 

*************************************************
CLD
*************************************************
0 Kudos
Message 4 of 10
(5,297 Views)

If you are lucky and have some additional information about your control (e.g. tab order) you might be able to use GetPanelAttribute ( panel_handle, ATTR_PANEL_FIRST_CTRL, &control_id ) and GetCtrlAttribute ( panel_handle, control_id, ATTR_NEXT_CTRL ) to cycle through all controls of your panel.

Message 5 of 10
(5,295 Views)
Solution
Accepted by lvrat

lvrat,

there are a couple of ways to detect some characteristics of a control at runtime. What wolfgang and I were suggesting was someting like this (code written by memory: there may be some errors in it):

 

int   ctrl, mode, style;

char   name[32];

// 'panelHandel' received from the other application

 

GetPanelAttribute (panelHandle, ATTR_PANEL_FIRST_CTRL, &ctrl);

while (ctrl) {

 

   // switch through the constant name

   GetCtrlAttribute (panelhandle, ctrl, ATTR_CONSTANT_NAME, name);

   if (!strcmp (name, "NUMERIC1")) {

   }

   else if (!strcmp (name, "NUMERIC2") {

   }

 

   // ALTERNATIVE: discriminate other characteristics

   GetCtrlAttribute (panelHandle, ctrl, ATTR_CTRL_STYLE);

   switch (style) {

      case CTRL_SQUARE_COMMAND_BUTTON:

      case CTRL_SQUARE_COMMAND_BUTTON_LS:

         GetCtrlAttribute (panelHandel, ctrl, ATTR_CTRL_MODE, &mode)

         if (mode == VAL_HOT) {

            // do something on the control ....

         }

         break;

      default:

         // do nothing

         break;

   }

 

   // Check to see if there are more controls on the panel

   GetCtrlAttribute (..., ..., ATTR_NEXT_CTRL, ...);

}

 

A list of control styles can be found here and in userint.h. Here the list of control modes.

 

There are a lot of attributes that can be used to discriminate among the controls in a panel. But the main doubt remains the same: have you tried accessing a control from a separate application via CVI panel handle?



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 6 of 10
(5,286 Views)

Well I have not tried accessing a control from a separate application via CVI panel handle....was going with the assumption but maybe a bad assumption 😞

But thanks for the steps on showing how to get the panel attribute and then the constant name.

*************************************************
CLD
*************************************************
0 Kudos
Message 7 of 10
(5,278 Views)

lvrat,

the CVI panel handle is internal to CVI application only. It appears obvious as the handle of the first panel loaded is always 1 even if you have several CVI applications running. I suppose you will need to use another technique to manipulate controls on the other app. Some help may come from tis attribute of CVI panels (top level panels only - no child panels):

 

HWND   swh;

GetPanelAttribute (panelHandle, ATTR_SYSTEM_WINDOW_HANDLE, (int *)&swh);

 

By searching the forum for 'System window handle' you will find several posts that can help you in developing the applications using windows messaging to interact between each other. This will imply some arrangements on both applications.

At this point, you may find other techniques more useful (or at least more documented) like network variables which can be used to message between applications.



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 8 of 10
(5,270 Views)

I also came across InstallCtrlCallback() and am thinking if this can be used in the second project? That way when the event is generated on the control that is in first project the registered event function in the second will be initiated. Has anyone used this....any suggestion if this is a good approach?

*************************************************
CLD
*************************************************
0 Kudos
Message 9 of 10
(5,247 Views)

lvrat, making a simple search on the forum for InstallWinMsgCallback returns a lot of threads discussing this function that you may wnat to read to gather information. As an example, this, this and this can be of some help to you. Also, this KnowledgeBase entry may be of much help.



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 10 of 10
(5,242 Views)