LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

does GetGraphCursorPosition() have old value when it is processed?

I am using a generic GRAPH and wanted to process the coordinate that the user clicks on. However, when the left-click callback is called, and I use GetGraphCursor(x,y), the returned (x,y) coordinates are of the previous location.
- I cannot use double-click, because that performs a different function.
- and when the user left-clicks, the cursor moves into the new position, but the GetGraphCursor() returns the previous position...

myCallback()
{
if (event == EVENT_LEFT_CLICK)
{
double x,y;

GetGraphCursor( panelID, PIXEL_GRAPH, 1,&x, &y );
SetCtrlVal( panelID, PIXEL_X, (int)x );
SetCtrlVal( panelID, PIXEL_Y, (int)y );
} else if (event == EVENT_LEFT_DOUBLE_CL
ICK) {
// do somthing else
}
}
0 Kudos
Message 1 of 4
(2,547 Views)
Hi,

The situation here is caused by the order on which the Callbacks are
being executed. When the user clicks on the graph the firts thing to
be executed is your own callback so the cursors have not yet recieved
and process the event when you get the cursor information.

The way arround this is to post an deferred callback that will get
executed after all the events are processed. Take lookat this
document:
"http://digital.ni.com/public.nsf/websearch/930C98B8579C786C86256DB4006A88F4?OpenDocument">Why
Do I R...

There is also a link there to some example code. It talks about table
controls, but it is the same situation.

I hope this helps.

Regards,

Juan Carlos
N.I.
0 Kudos
Message 2 of 4
(2,547 Views)
Thank you! That fixed it perfect. I modified my code into something
like the attached file, and it got me my desired effect!

Except for the double-click. It seems like double-click is a
left-click first... I'll work on this...
0 Kudos
Message 3 of 4
(2,547 Views)
You are right,

A double-click will generate a left-click event first and then a
double click; this is just the nature of the Windows event structures.
In most other controls you can use the EVENT_COMMIT to go around this,
but in this particular application you will probably need to do some
programming or seting some flags to detect what action to take; You
could also move to a RIGHT_CLICK option isntead of a DOUBLE_CLICK....
just an idea.

Good Luck!

Juan Carlos
0 Kudos
Message 4 of 4
(2,547 Views)