LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

event for 'command button up' needed

Solved!
Go to solution

Hi,

 

I have a command button that should have the following action:

 

while pushed down, zoom a graph into a predefined region, 

if released, zoom back

 

I do not want to use a toggle button.

 

What I did: on EVENT_LEFT_CLICK: SetAxisScalingMode to desired region, in case of EVENT_LEFT_CLICK_UP set scaling mode to original region.

 

Hence, as long as the user pushes the button, the graph is zoomed in, as desired.

 

Now, there is a little drawback: the user may (unwittingly) 'cheat' and, while pushing the button, move the mouse cursor away: in this case there will be no left_click_up event anymore...  I tried using 'lost_focus' but this happens only much later, when a new control is clicked. And I tried EVENT_MOUSE_POINTER_MOVE, but this is not practical either: any shiver will zoom out.

 

Does anybody have a suggestion/trick to achieve the desired result?

 

Thanks!

0 Kudos
Message 1 of 13
(5,439 Views)

Hey Wolfgang - 

 

You could set a global flag in the EVENT_LEFT_CLICK of the button callback.  Then in the EVENT_LEFT_CLICK_UP event of the panel callback, you could check if the global flag is set.  If so, zoom out and clear the flag.

 

If the user moves completely off the panel, you'll be in trouble - otherwise it should work.

 

NickB

National Instruments 

0 Kudos
Message 2 of 13
(5,430 Views)

Hi Nick,

 

thanks - I was considering this approach, but because it does not fully solve the request, I was (and still am...) hoping for some other idea. Another (rejected) possibility could be to use timer ticks, but I didn't like it for the complexity involved. Hm...

 

 

0 Kudos
Message 3 of 13
(5,429 Views)
Could you put the logic into the panel callback and not the control callback, using GetCtrlBoundingRect(..) to determine when the user has the mouse cursor over the button?  I believe the panel still receives click events when the user is interacting with a control, at least in most cases.
0 Kudos
Message 4 of 13
(5,402 Views)

Hi TStanley,

 

Thanks! Your suggestion is very similar to what NickB suggested? This approach maximizes the chances to catch the 'up' event for the panel is larger than the button; still it is not foolproof, the user could move the mouse off the panel and release the button only then...

0 Kudos
Message 5 of 13
(5,381 Views)
Solution
Accepted by topic author Wolfgang
You could then use EVENT_MOUSE_POINTER_MOVE along with GetCtrlBoundingRect() to know when the user had moved the mouse pointer off of the button.  You would have to use the panel callback to do this, as you would not get a EVENT_MOUSE_POINTER_MOVE event in the control callback once the mouse cursor had moved off the button.  To be extra sure, you could also look for EVENT_LOST_FOCUS just in case the user is somehow able to get the mouse cursor off the panel without triggering an EVENT_MOUSE_POINTER_MOVE event somewhere off of the button first.
Message 6 of 13
(5,378 Views)

Hi TStanley,

 

this indeed solved my problem. Thanks!

 

Btw, using this approach there is no need to check for lost focus - I found no possibility not to receive an EVENT_MOUSE_POINTER_MOVE event when leaving the Zoom button with the mouse.

 

Wolfgang

0 Kudos
Message 7 of 13
(5,349 Views)

So, here comes the Postscriptum...

 

While the problem is solved, function-wise, there is an optical drawback; I don't know if it is caused by Windows or CVI - in any case I would ask NI to look at it and may be change the behavior...

 

If you push the button and leave the button with mouse cursor depressed, the button returns to its off position (not depressed); hovering around and then returning to the same button, still with the mouse cursor depressed, the button is depressed again, automatically. (It does not respond to a left click, because there is no additional click)

 

This does not happen if you start somewhere on the panel, click and move with the depressed mouse cursor onto the button: the button remains in its unclicked, not depressed state.

 

This is very depressing 🙂 But seriously, it is somewhat inconsistent, at least for the user.

 

Wolfgang

 

0 Kudos
Message 8 of 13
(5,347 Views)

Wolfgang wrote: 

If you push the button and leave the button with mouse cursor depressed, the button returns to its off position (not depressed); hovering around and then returning to the same button, still with the mouse cursor depressed, the button is depressed again, automatically. (It does not respond to a left click, because there is no additional click)

 

This does not happen if you start somewhere on the panel, click and move with the depressed mouse cursor onto the button: the button remains in its unclicked, not depressed state.



Hi Wolfgang, this behaviour is consistent with every Windows application, not only within CVI: functions are launched when you release the buttons; while you keep the mouse button button pressed and move the pointer, the buttons on the screen operate as you have noted but with no function is launched (I suppose this is intended as a chance for the user to abandon a function: if you press a button on a panel, then move the mouse and release the mouse button no function is executed).



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 9 of 13
(5,338 Views)

Hi Roberto,

 

Thanks! I never played with the mouse cursor like this before... You are right, I just verified, this observation is typical Windows behavior.

 

However, in my case the intended behavior is different, trying to simulate a pushbutton: I zoom in when a left-click is received, and regularly zoom out if a mouse-up event is received: so there is no possibility for the user to 'cancel' the operation... just like a door bell: if you push the button, it starts making noise until you release the button.

 

Unfortunately, there is no such function in CVI.

Message Edited by Wolfgang on 04-06-2010 03:42 PM
0 Kudos
Message 10 of 13
(5,332 Views)