Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

User selection of an area on a CNiGraph

I need to allow the user to select a rectangular area of a (plot area of a)
CNiGraph in 'rubber-band' fashion using the mouse. The zoom functionality
(CNiGraph::TrackZoomRectXY) is the effect I'm looking for, except that I
don't want it to zoom the graph. I just want it to return the CRect or
similar.
Thanks.
0 Kudos
Message 1 of 3
(3,121 Views)
There's no direct support for this in the graph, but it's not too hard to implement this yourself. Off the top of my head, these would be the steps to do this:



  1. Handle the WM_LBUTTONDOWN message for the graph. Store the x/y coordinates of where the user clicked and call SetCapture on the graph's window handle.


  2. Handle the WM_MOUSEMOVE message for the graph. Draw the rubber band rectangle starting with the coordinates that were stored in the first step and the coordinates of where the mouse is now. Draw the rectangle such that it is reversible - the easiest way to do this is to call SetROP2 on the device context with R2_NOT. Before you draw this rectangle, you should erase the old rectangle if there w
    as one drawn in a previous WM_MOUSEMOVE message. You can do this by just re-drawing the rectangle with the previous coordinates with the R2_NOT ROP mode.


  3. Handle the WM_LBUTTONUP message for the graph. Erase the rubber band (see above), call ReleaseCapture on the graph's window handle, and calculate the current selection rectangle with the initial coordinates that were saved in step 1 and the coordinates of where the mouse is now.




Hope this helps.

- Elton
0 Kudos
Message 2 of 3
(3,120 Views)
Thank you Elton for your answer but I already saw this post. And the problem with this is that WM_LBUTTONDOWN, WM_MOUSEMOVE and WM_LBUTTONUP do not allow you to access the value of the plots in the graph3D. It is only linked with pixels on the screen. By this way I agree that I can draw a rectangle exactly where I want.
But what I really want to do is to use PlotMouseDown and PlotMouseMove (as shown in the Measurement Studio example "Region of Interest for NiGraph3D")and at the same time draw a rectangle to see the frame of the user selection. And the problem with PlotMouseMove is that you don't have anymore the access to the screen pixels. My rectangle is drawn on the wrong place (even out of the graph control) with a wrong size.
That is quite difficult to e
xplain, I hope you will catch my question.
If you can help me, Thanks a lot
ALia
0 Kudos
Message 3 of 3
(3,120 Views)