LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Beginner - Multiple buttons same callback function

I have a problem to solve, and I am a beginner in LabWindows.

I built a panel that has 2 buttons. All this buttons call the same CVICALLBACK function. During the EVENT_LEFT_CLICK event I have to know which button was pressed.

It follows the function that I implemented to do the test.

int CVICALLBACK pressedIndicatorButton (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2) {
    int val;          

    switch (event) {
        case EVENT_LEFT_CLICK:

            GetCtrlVal(panel, control, &val);
            switch (val) {
                case INDICATOR_BUTTONCHART:
                    MessagePopup("Alert", "Alert");
                    break;
                case INDICATOR_BUTTONKNOB:
                    break;
            }
            break;
    }
    return 0;
}

The constant name of the buttons are BUTTONCHART and BUTTONKNOB. The contant name of the panel that the buttons are in is INDICATOR.

What is it wrong in the code?

Thank you in advance!
0 Kudos
Message 1 of 2
(3,410 Views)

Hi Oliveira,

You should put the control parameter in your switch statement:

switch (control){
    case INDICATOR_BUTTONCHART:
        MessagePopup("Alert", "Alert");
        break;
    case INDICATOR_BUTTONKNOB:
        break;
}

Message 2 of 2
(3,408 Views)