05-04-2013 05:07 AM
Hello,
I'v programmed a code:
static int panelHandle;
static int flag = 0;
static int picID;
int CVICALLBACK ProcAnimate (int panelHandle, int controlID, int event, void *callbackData, int eventData1, int eventData2);
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "testanimate.uir", PANEL)) < 0)
return -1;
picID = AnimateCtrl_ConvertFromPictRing(panelHandle, PANEL_PICTURERING);
InstallCtrlCallback(panelHandle, PANEL_PICTURERING, ProcAnimate, NULL);
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
int CVICALLBACK ProcAnimate (int panelHandle, int controlID, int event,
void *callbackData, int eventData1, int eventData2)
{
int res ;
if (event == EVENT_LEFT_DOUBLE_CLICK)
{
if (flag == 0)
{
res = AnimateCtrl_SetAttribute(panelHandle, picID, ATTR_ANIMATE_FRAME_INTERVAL, 0.4);
res = AnimateCtrl_SetAttribute (panelHandle, picID, ATTR_ANIMATE_ENABLED, 1);
flag = 1;
}
else
{
AnimateCtrl_SetAttribute (panelHandle, picID, ATTR_ANIMATE_ENABLED, 0);
flag = 0;
}
}
return 0;
}
Hope double clicked the picture ring it can play animation. but I found that the variable res got an error (-45). What is wrong?
David
05-04-2013 07:55 PM
I've make some test, I find that once install a callback function for an animate control, it will never play animation.
05-05-2013 11:41 PM
Hello David,
Ive rarely used the animation control but error -45 means "The control type passed is not a valid type", so I suppose you need to check the control ID you are passing to the function and check also that AnimateCtrl_ConvertFromPictRing returns a valid value.
Additionally, the help for the instrument specifically states that the animation control can have a callback, which in case receives two additional events. This should mean that you can obtain a behaviour like the one you want. I would suggest two tests:
1, Try not to install the callback to the control and see if the animation control works as expected
2. Try installing the callback in the UIR editor instead of programmatically
Later in the office I will make some test and add some more ints if I note something about this matter.
05-06-2013 02:16 AM
Ok, I tested with the sample located in samples\userint\custctrl\animate\animsample.cws and was able to modify it to start with a double click and stop with a single click. The control callback correctly receives and interpret the events.
I suggest you to take a look at the sample and try elaborating on it (hint: the rocket control if located to the right of the canvas; widen the panel to see it)
05-06-2013 05:26 AM
Hello Roberto,
The attachment is a simple code I've coded. I just want to do such a thing: once double click the picture ring, it can play animation. But whatever doing something, it always say the control type is error.
David
05-06-2013 05:46 AM - edited 05-06-2013 05:49 AM
Attached your project modified and working. The solution is to set control callback in the editori instead of using InstallCtrlCallback (it is basically one of the suggestions I already gave to you: you could have tried it and solution your problem earlier )
Alternatively, if you want/need to dynamically install the callback, set it before creating the animation control and the system will still be working.
When dealing with custom controls, you must understand that almost all of them use a special callback to accomplish control function. That callback is chained to a control callbak that eventually exists, and must not be modified afterwards, otherwise control behaviour will be affected (cancelled like in your case, you could also get GPFs or other errors for more complex controls). I have it as a general rule for myself: when I need to set some attribute for controls used to generate custom controls, I set it before passing the control to instrument functions.
05-06-2013 08:48 PM
Hi Roberto,
Thank you very much for your reply.
David