LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Using same control call back from different tabs

Solved!
Go to solution

Hi,

 

I'm fairly new at this so bare with me for a sec... 

 

I have a situation were I'm using multiple Tabs with the exact same control buttons in each of them.  Since the buttons have the same function I would like to use the same callback.  I understand that each TAB is considered a panel and has its own panel handle.

 

My problem is that I want the call back to differentiate between the OK button in TAB1 and the one in TAB2.  The panel handle passed down to the call back is (from what I can tell) the panel handle for the tab which is great but it does not have a constant assign to it in the header file.  How do I insure that TAB1 always has the panel handle 2 and TAB2 always has the panel handle 3, etc...

 

 

Example:  When I click on OK in TAB1 the panel handle sent to the btnOK callback is = 2.  If I click OK in TAB2 the panel handle is = 3.  I want to switch between the to OK buttons but do not want to use hard coded integer.

 

int CVICALLBACK btnOK (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)

{

switch (event)

{

case EVENT_COMMIT:

 

switch (panel){

  case 2:                  <----I don't want a number here but a constant

"do this"

 

case 3: 

"do this"

 

};  

 

}

return 0;

 

The easy way would be to have a callback for each of the buttons.  If that's the only way to go that that's what I'll do but I'm interested in what you think.

 

Thanks!

 

 

0 Kudos
Message 1 of 2
(3,252 Views)
Solution
Accepted by topic author nlebouthillier

Hi,

I can think of at least three ways to obtain what you want.

 

Solution A: rely on tab page constant name (since you can retrieve it given the panel handle)

Inside the callback insert this code:

 

char   name[64];

 

GetPanelAttribute (panel, ATTR_CONSTANT_NAME, name);
if (!strcmp (name, PAGE1)) {

    // Code for first tab page

}

else if (!strcmp (name, PAGE2)) {

    // Code for second tab page

}

.... code for additional pages

 

Solution B: rely on tab attributes

 

int   parent, index;

 

GetPanelAttribute (panel, ATT_PANEL_PARENT, &parent);

GetActiveTabPage (parent, PANEL_TAB, &index);

switch (index) {

    case 0:

        // Code for the first tab page

        break;

    case 1:

        // Code for the second tab page

        break;

    .....   add extra pages code

}

 

Solution C: use callbackData parameter for the buttons

This solution requires code in two different program sections

 

* When loading the panel with the tab control

 

int    pnlH;

 

GetPanelHandleFromTabPage (panel, PANEL_TAB, 0, &pnlH);

SetCtrlAttribute (pnlH, PAGE1_BUTTON, ATTR_CALLBACK_DATA, (void *)1);

GetPanelHandleFromTabPage (panel, PANEL_TAB, 1, &pnlH);

SetCtrlAttribute (pnlH, PAGE2_BUTTON, ATTR_CALLBACK_DATA, (void *)2);

.... and so on

 

* In the button callback

 

switch ((int)callbackData) {

    case 1:

        // Code for the first tab page

        break;

    case 2:

        // Code for the second tab page

        break;

    .....   add extra pages code

}

 

Message Edited by Roberto Bozzolo on 05-22-2010 09:21 AM


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