03-18-2013 05:55 PM
I created a command button via the Create->Command Button menu option. It was working fine, but somewhere in my mucking around, I've gotten it so it acts as though it's pressed when I simply move the mouse key over it. I can't find an attribute that would cause this behavior. Can anyone help me with this?
Thanks.
Solved! Go to Solution.
03-19-2013 12:16 AM
On what events are you reacting.... could it be that you changed the callback routine to trigger on GOT_FOCUS or LOST_FOCUS instead of EVENT_COMMIT?
03-19-2013 12:38 AM
Most probably you have some code that is not tied to any event and so it's fired on EVENT_MOUSE_POINTER_MOVE events that are received by the control callback every time the pointer passes over it. Place a breackpoint inside the control callback and look at 'event' variable value, searching it in the list of events.
03-19-2013 09:04 AM
Roberto -
You're definitely onto something. Event comes back as 33, which matches EVENT_MOUSE_POINTER_MOVE (I looked it up in userint.h).
When I first created this button, it wasn't doing that. I just checked my defaults, and it's not selected in there.
So...how do I correct this? I can't find anything when I edit the command button.
Thanks!
03-19-2013 09:24 AM
It's not an option in control properties, it's how your code is structured:
int CVICALLBACK Impostazione (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { // This code is executed on any event. EVENT_MOUSE_POINTER_MOVE // is the most frequent one but not the only one DoSomething (); switch (event) { case EVENT_COMMIT: // This code is executed only when you press the button DoSomething (); break; } return 0; }
The first DoSomething () is normally to be avoided...
03-19-2013 09:27 AM
I see. Does the creation of automatic variables count as "doing something?" Because at this point, that's all I have up there.
03-19-2013 09:37 AM
mzimmers,
Could we see the callback function code? That might help shed some light on the situation.
03-19-2013 09:46 AM
int CVICALLBACK StartButtonCB (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int line, x, y; int i; int lockBusy; switch (event) { case EVENT_COMMIT: while (CmtGetLockEx(inUse, 0, 100, &lockBusy)); // wait for lock in 100 ms durations. i = 0; while (sscanf(callbackData, "%d %x %x", &line, &x, &y) > 0 && (i < CONST_POINTS)) { constArray[0][i] = x; constArray[1][i] = y; ++i; } plot(i); // plot the points. CmtReleaseLock (inUse); break; case EVENT_RIGHT_CLICK: break; } return 0; }
Thanks for looking.
03-19-2013 10:23 AM
This callback responds only to commit and right-click events, so what lets you think the callback is "activated" while hovering the mouse on the button? How you detect this fact?
03-19-2013 10:51 AM
I've just re-read the replies in this thread, and I think I know realize what was happening.
If I understand correctly now, the callback is executed on ANY event, not just the types specified in the callback routine, or the default types upon creation of the control?
I had a breakpoint at the top of my CB routine, and it was getting hit whenever I'd mouse-over the button. Hence, my confusion.
So...is there a way to program the object NOT to respond to a mouse-over, or is that just the way the package works?
Thank you all for the answers.