From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

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,630 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,621 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,620 Views)

Hi, all:

I try your suggestions and it works here now.

Thanks!

Brad

0 Kudos
Message 4 of 5
(4,593 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,583 Views)