LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

problem with safely obtaining mouse coordinates

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 Smiley Happy

0 Kudos
Message 1 of 9
(4,474 Views)

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

0 Kudos
Message 2 of 9
(4,435 Views)

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 Smiley Very Happy

 

-> use a timer callback and the function GetGlobalMouseState instead of GetGraphCoordsFromPoint 

0 Kudos
Message 3 of 9
(4,424 Views)

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 );

0 Kudos
Message 4 of 9
(4,411 Views)

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 );

 

 

0 Kudos
Message 5 of 9
(4,402 Views)

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

0 Kudos
Message 6 of 9
(4,370 Views)

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 Smiley Wink - 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.)

0 Kudos
Message 7 of 9
(4,364 Views)

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().

--
Martin
Certified CVI Developer
0 Kudos
Message 8 of 9
(4,356 Views)

Thank you Martin,

 

but is has already been suggested earlier by Al...Smiley Wink

0 Kudos
Message 9 of 9
(4,353 Views)