LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to change the Callback function of a GUI button?

Solved!
Go to solution

I would like to change the callback function associated with a GUI button dynamically in the programming way.

 

Here is the code piece I tried, but it does not seem to work:

 

const char* pstrLabelSaveJpeg = "SaveJpegCb";

SetCtrlAttribute(pahel_id, ctrl_id ,ATTR_LABEL_TEXT, pstrLabelSaveJpeg);

 

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

0 Kudos
Message 1 of 5
(4,637 Views)
Solution
Accepted by topic author Vineyard

The attribute you used is about the "label" of the button.

It is just an appearence attribute. You can write your own name on it, but that does not change the callback function.

 

You should change the ATTR_CALLBACK_FUNCTION_POINTER attribute, and you should not pass the function name as a string.

 

So your function call will look like this:

SetCtrlAttribute(pahel_id, ctrl_id, ATTR_CALLBACK_FUNCTION_POINTER, SaveJpegCb);

 

Of course, you have to declare the SaveJpegCb function somewhere above that line.

I think you have already done that.

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 5
(4,628 Views)
Solution
Accepted by topic author Vineyard

Your code does not work because the attribute you are trying to change is the text label of a control, not it's callback function...

 

You may want to have a look at the attribute ATTR_CALLBACK_FUNCTION_POINTER instead.

 

 

Oh, I see that Eren was faster Smiley Happy

0 Kudos
Message 3 of 5
(4,627 Views)

Hi, all:

I try your suggestions and it works here now.

Thanks!

Brad

0 Kudos
Message 4 of 5
(4,600 Views)
Solution
Accepted by topic author Vineyard
If your problem is solved please mark the solution.
Thanks 😉
S. Eren BALCI
IMESTEK
0 Kudos
Message 5 of 5
(4,590 Views)