LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with transferring values into CVICALLBACK function

Why does value not transfer from dynamically created ring control into the CVICALLBACK function?
 
 
I created ring control so:
 
 int i,control;
 char *Program_mode[2]={"Control Mode","Monitoring Mode"};
    Toolbar_New (panel, menuBar, "", 0, 0, 1, 1, &Window_toolbar);
 Toolbar_InsertItem (Window_toolbar, END_OF_LIST, kRing, 1, "Program Mode",
        kControlCallback, 0, ProgramModeCallback, NULL, "");
    // get panel, control values               
    Toolbar_GetCtrlFromDescription(Window_toolbar, "Program Mode", &panel, &control); 
      // insert program modes options: "Control Mode","Monitoring Mode"
      for (i=0; i<=1; i++)
      {
            InsertListItem (panel, control, -1, Program_mode[i], i);
        }
 
CVICALLBACK function is:
 
int CVICALLBACK ProgramModeCallback (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 int Monitoring_mode;
 switch (event)
 {
  case EVENT_COMMIT:
         GetCtrlVal(panel, control,&Monitoring_mode);
         if (Monitoring_mode)
         {
            SetCtrlAttribute (panel,control,ATTR_TEXT_BGCOLOR, 0x00B7FFB7); // light green
         }
         else
         {
            SetCtrlAttribute (panel,control,ATTR_TEXT_BGCOLOR, 0x00FF80FF); // light red
         }
     
        break;
 }
 return 0;
}
 
 
The "panel" value doesn't transfer into the function.
 
But if I create this control manually It transfers excellent.
 
 
At the left of the attached picture there is the dynamically created ring control and at the right -  manually created ring control.
0 Kudos
Message 1 of 3
(3,333 Views)
It seems to me that the toolbar is actually a panel itself (a child panel if it is docked on a panel); for this reason the panel variale you are using does not refere to the panel your control is on (you could add a breakpoint and examine 'panel' value, which should be different from the panel handle). Given this, you should be able to get the handle of the panel he toolbar is docked on using TOOLBAR_ATTR_ATTACHED_PANEL attribute in Toolbar_GetAttribute. In case your toolbar is floating (i.e. undoked) you must find another method to get the correct panel handle, since that attribute will return 0; you could for example pass the panel handle as the callbackData parameter of the toolbar control.


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 2 of 3
(3,318 Views)

The problem was solved by using global variables.

0 Kudos
Message 3 of 3
(3,226 Views)