LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to specify callback data for generated GUI elements?

How to access program generated GUI elements?

Rather than teadiously laying out an operator panel control by control I decided to generate the panel under program control. The panel has five columns of passive controls, and one column of buttons. (see code below). The actual panel generated quite nicely, and I have no problem accessing the input data controls and output LEDs.

My problem is, I haven't figured out to write a callback to handle the column of button presses. When I button is pressed, I need to have the index of the row passed to the callback. The generated control ID for the button is meaningless. I know how to pass back a pointer to a struct containing these controls, but how do I dynamically find out the row index of the button pressed?

Thanks in advance for any help on this....

Doug Wendelboe

    for (i=20, j=70; i>0; i--, j+=24)
    {
                sprintf(bfr, "Slot %2.2i", i);
                slotID[i-1] = NewCtrl (pHandle, CTRL_TEXT_MSG, bfr, j, SLOT_LABELS);
                SetCtrlAttribute (pHandle, slotID[i-1], ATTR_TEXT_BOLD, 1);
                SetCtrlAttribute (pHandle, slotID[i-1], ATTR_TEXT_BGCOLOR, 0x00E0DFE3);
        
                TrayID[i-1]  = DuplicateCtrl (pHandle, PROC_SETUP_TRAYNO, pHandle, "", j, SLOT_LABELS+50);
                SetCtrlAttribute (pHandle, TrayID[i-1], ATTR_WIDTH, 100);
                SetCtrlAttribute (pHandle, TrayID[i-1], ATTR_CTRL_VAL, "");

                LotID[i-1]   = DuplicateCtrl (pHandle, PROC_SETUP_TRAYNO, pHandle, "", j, SLOT_LABELS+160);
                SetCtrlAttribute (pHandle, LotID[i-1], ATTR_WIDTH, 150);
                SetCtrlAttribute (pHandle, LotID[i-1], ATTR_CTRL_VAL, "");

                TubeNos[i-1] = DuplicateCtrl (pHandle, PROC_SETUP_TUBES, pHandle, "", j, SLOT_LABELS+320);
                SetCtrlAttribute (pHandle, TubeNos[i-1], ATTR_WIDTH, 60);
                SetCtrlAttribute (pHandle, TubeNos[i-1], ATTR_CTRL_VAL, 0);
 
                ConfirmID[i-1] = DuplicateCtrl (pHandle, PROC_SETUP_CONFIRM, pHandle, "", j, SLOT_LABELS+385);
                SetCtrlAttribute (pHandle, ConfirmID[i-1], ATTR_WIDTH, 45);
                SetCtrlAttribute (pHandle, ConfirmID[i-1], ATTR_LABEL_TEXT, "Confirm");
                SetCtrlAttribute (pHandle, ConfirmID[i-1], ATTR_LABEL_POINT_SIZE, 10);
                InstallCtrlCallback (pHandle, ConfirmID[i-1], psConfirmButtons, 0);
//              SetCtrlAttribute (pHandle, ConfirmID[i-1], ATTR_CALLBACK_DATA, ???);
         
                ledOKID[i-1] = DuplicateCtrl (pHandle, PROC_SETUP_LED_OK, pHandle, "", j+2, SLOT_LABELS+440);
                SetCtrlAttribute (pHandle, ledOKID[i-1], ATTR_ON_COLOR, VAL_DK_GRAY);
    }
    


0 Kudos
Message 1 of 6
(3,713 Views)
Hi Doug,
 
Assuming that i represents the row, why not just pass i (or maybe i - 1) as the callback data?
 
   InstallCtrlCallback (pHandle, ConfirmID[i-1], psConfirmButtons, (void *)(i-1));

Don't let the void * datatype of that parameter dissuade you. Usually, callback data are pointers, but they don't have to be. Any 32-bit value will work.
 
Luis
 
0 Kudos
Message 2 of 6
(3,711 Views)

I seem to understand that you have 20 rows of controls, and getting the row number can be enough for you. If this is the case, you can pass the row number this way:

SetCtrlAttribute (pHandle, ConfirmID[i-1], ATTR_CALLBACK_DATA, (void *)i);

and retrieve it in button callback simply casting callbackData parameter to an int:

row = (int)callbackData;

Consider also that you can set the callbackData within InstallCtrlCallback function:

InstallCtrlCallback (pHandle, ConfirmID[i-1], psConfirmButtons, (void *)i);



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 6
(3,706 Views)

Thanks to both of you for your response.

I guess I'm still confused. If variable "i" is local to the function drawing the control during program initialization, won't "i" go away after the function is done? I'm thinking that any callback data will point to where "i" was, and cause some kind of addressing error?

 

0 Kudos
Message 4 of 6
(3,703 Views)
No, by casting it to a void pointer you are passing the nude value instead of the variable address: the callback data will not use it as an address to access the local variable (in which case a fatal error is granted Smiley Wink ) but it uses the simple value.


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 5 of 6
(3,699 Views)

OK, I think I got it. So the actual value of "i" when the button is generated is saved (as a constant value) and passed to the callback when the appropriate button is pressed.

Thanks, I think that will do it.

DOug

0 Kudos
Message 6 of 6
(3,696 Views)