10-23-2010 12:00 PM
Hi,
I am encountering a problem and would be grateful for assistance...
On a panel I have a xy graph. I am using a panel callback and the function GetGraphCoordsFromPoint to turn a coordinate text display on and off depending on the mouse position using the following approach:
int CVICALLBACK PanelEvents ( int panel...
{
if ( event == EVENT_MOUSE_POINTER_MOVE )
{
if ( GetGraphCoordsFromPoint ( panel, PANEL_GRAPH, ... )
{
SetControlVisible ( panel, PANEL_TEXTBOX,...
If the mouse is over the graph, the text display is on, otherwise it's off. That's working fine in principle.
However, if the mouse is moved very fast and leaves the panel it may happen that the text display remains visible because no event is generated while the mouse is over the panel but not over the graph.
Suggestions (in particular solutions) are welcome ![]()
10-25-2010 08:44 AM - edited 10-25-2010 08:51 AM
Wolfgang:
As you have discovered, EVENT_MOUSE_POINTER_MOVE works only when the mouse is over the CVI panel. In order to get mouse events off the CVI panel, you need to use the "obsolete" extended mouse events.
CVI help for EnableExtendedMouseEvents states the following:
This function is obsolete. National Instruments recommends that you instead use the following built-in LabWindows/CVI events: EVENT_MOUSE_POINTER_MOVE, EVENT_LEFT_CLICK_UP, and EVENT_RIGHT_CLICK_UP. Use EnableExtendedMouseEvents if you need to get event information when a user releases the left or right mouse buttons outside of a LabWindows/CVI panel.
Here's a sample program I posted earlier in another message.http://forums.ni.com/t5/LabWindows-CVI/move-panel/m-p/1185097#M48067
10-25-2010 09:58 AM
Al, thanks again!
I did not like the idea of going back to deprecated functions (and I do not need the left_click_up or right_click_up events) - but there is a nice way out, as I have just discovered, and the NI example moustate explains it all
-> use a timer callback and the function GetGlobalMouseState instead of GetGraphCoordsFromPoint
10-25-2010 11:00 AM
I have to correct my previous posting...:
> use a timer callback and the function GetGlobalMouseState in addition to GetGraphCoordsFromPoint
So my current solution is a panel callback as outlined in the first message above; this approach has the nice feature that the plot area of the graph is used excluding the graph frame
As a safety net I am using a timer callback (permitting a relatively large interval of say 0.1 Hz) a la
if ( event == EVENT_TIMER_TICK )
{
GetRelativeMouseState ( panel, PANEL_GRAPH, &x_coordinate, &y_coordinate, NULL, NULL, NULL );
if ( ( x_coordinate < 0 ) ||
( y_coordinate < 0 ) ||
( x_coordinate > graph_width ) ||
( y_coordinate > graph_height ) )
{
SetControlVisible ( panel, PANEL_TEXTBOX, FALSE );
10-25-2010 11:55 AM
ach... I just started to be happy with the solution when I discovered a problem:
while GetRelativeMouseState returns the coordinates even if the mouse is not over the control or the panel - it does require that the panel is not minimized, otherwise it will complain...
Why does this function require a non-minimized panel?
OK, for future reference, here is the updated snippet:
if ( event == EVENT_TIMER_TICK )
{
SetBreakOnLibraryErrors ( FALSE );
GetRelativeMouseState ( panel, PANEL_GRAPH, &x_coordinate, &y_coordinate, NULL, NULL, NULL );
SetBreakOnLibraryErrors ( TRUE );
if ( ( x_coordinate < 0 ) ||
( y_coordinate < 0 ) ||
( x_coordinate > graph_width ) ||
( y_coordinate > graph_height ) )
{
SetControlVisible ( panel, PANEL_TEXTBOX, FALSE );
10-27-2010 02:27 AM
Hi, Wolfgang
is it possbile that you use graph callback to obtain the mouse move event. then display or hide the control you which want accordingly. ?
B.R
gerry
10-27-2010 04:19 AM
Hi Gerry,
indeed it's possible to use the EVENT_MOUSE_POINTER_MOVE event, however, if you use it in the control callback, the callback will not be called if the mouse is not over the control - and this actually is the purpose of this thread
- I want to toggle the visibility of a textbox (showing the cursor coordinates) located at the cursor position.
So the task is to find out when the mouse is over the control and when not. Because the control callback is limited to the area of the cotnrol, it can not be used here. (The graph does not need to have the focus, so you can not use the lost focus event.)
10-27-2010 05:55 AM
You could try the (allegedly obsolete!) Extended Mouse Events functions in the Programmer's Toolbox. If you EnableExtendedMouseEvents() for a control, the control callback should receive EVENT_MOUSE_MOVE events, even if the mouse is not over the control, until such time as you DisableExtendedMouseEvents().
10-27-2010 06:36 AM
Thank you Martin,
but is has already been suggested earlier by Al...